Loading...
Searching...
No Matches
matmul_cudnn.h
Go to the documentation of this file.
1// SPDX-License-Identifier: AGPL-3.0-only
2// Copyright (C) 2026 Artificial Intelligence Techniques, S.L. and Roberto López González
3
4#pragma once
5
6#ifdef OPENNN_HAS_CUDA
7
9
11{
12
13// Optional cuDNN provider for GEMMs that its engine set runs faster than
14// cuBLASLt. matmul_backend.cpp owns timing, verification, caching and final
15// selection; this provider only builds and executes cuDNN graphs.
16struct Problem
17{
18 int m = 0;
19 int n = 0;
20 int k = 0;
21
22 cublasOperation_t transA = CUBLAS_OP_N;
23 cublasOperation_t transB = CUBLAS_OP_N;
24 cublasLtEpilogue_t epilogue = CUBLASLT_EPILOGUE_DEFAULT;
25
26 cudaDataType_t dtype_a = CUDA_R_32F;
27 cudaDataType_t dtype_b = CUDA_R_32F;
28 cudaDataType_t out_dtype = CUDA_R_32F;
29
30 // Zero derives the leading dimension from m, n and k.
31 int lda = 0;
32 int ldb = 0;
33 int ldd = 0;
34
35 bool beta_is_zero = true;
36};
37
38// Opaque: matmul_backend.cpp holds a pointer and never a definition, so
39// cudnn_frontend.h stays inside this translation unit.
40class Plan;
41
42// A declined problem returns nullptr and remains on cuBLASLt.
43// Rebuild one cached engine without enumerating the complete candidate set.
44Plan* create(const Problem&, int64_t plan_index = -1) noexcept;
45void destroy(Plan*) noexcept;
46
47// Candidates are valid engine configurations within the workspace cap.
49{
50 int64_t plan_index = -1;
51 size_t workspace_bytes = 0;
52 string_view name;
53};
54
55int candidate_count(const Plan*) noexcept;
56CandidateInfo candidate(const Plan*, int) noexcept;
57
58// Uses cuBLASLt operand order and returns false when the caller should fall back.
59bool run(Plan*, int candidate,
60 const void* a, const void* b, const void* bias, void* d,
61 void* workspace) noexcept;
62
63// OPENNN_CUDNN_MATMUL_VERBOSE: report what was offered and what was chosen.
64bool verbose() noexcept;
65
66}
67
68#endif
Definition matmul_cudnn.h:11
Plan * create(const Problem &, int64_t plan_index=-1) noexcept
void destroy(Plan *) noexcept
int candidate_count(const Plan *) noexcept
CandidateInfo candidate(const Plan *, int) noexcept
bool verbose() noexcept
bool run(Plan *, int candidate, const void *a, const void *b, const void *bias, void *d, void *workspace) noexcept
Definition matmul_cudnn.h:49
string_view name
Definition matmul_cudnn.h:52
size_t workspace_bytes
Definition matmul_cudnn.h:51
int64_t plan_index
Definition matmul_cudnn.h:50
Definition matmul_cudnn.h:17
int k
Definition matmul_cudnn.h:20
cudaDataType_t dtype_b
Definition matmul_cudnn.h:27
int ldd
Definition matmul_cudnn.h:33
cublasOperation_t transB
Definition matmul_cudnn.h:23
bool beta_is_zero
Definition matmul_cudnn.h:35
cublasLtEpilogue_t epilogue
Definition matmul_cudnn.h:24
cublasOperation_t transA
Definition matmul_cudnn.h:22
int ldb
Definition matmul_cudnn.h:32
cudaDataType_t dtype_a
Definition matmul_cudnn.h:26
int n
Definition matmul_cudnn.h:19
cudaDataType_t out_dtype
Definition matmul_cudnn.h:28
int lda
Definition matmul_cudnn.h:31
int m
Definition matmul_cudnn.h:18