| 40 | // matrix matrix multiplication |
| 41 | template <typename T> |
| 42 | inline void DnMatDnMat( |
| 43 | DeviceBlasHandle& cublas_H, |
| 44 | DeviceDnTen<T>& matC, const DeviceDnTen<T>& matA, const DeviceDnTen<T>& matB, |
| 45 | const cublasOperation_t transa = CUBLAS_OP_N, const cublasOperation_t transb = CUBLAS_OP_N, |
| 46 | const double alpha = 1.0, const double beta = 0.0 |
| 47 | ) { |
| 48 | // check the dimension if we define SAFE |
| 49 | #ifdef SAFE_MODE |
| 50 | if(matA.num_dims!=2){ |
| 51 | std::cout<<"the dimension of A is wrong! A dims: "<< matA.num_dims <<std::endl; |
| 52 | return; |
| 53 | } |
| 54 | else if (matB.num_dims!=2) |
| 55 | { |
| 56 | std::cout<<"the dimension of B is wrong! B dims: "<< matB.num_dims <<std::endl; |
| 57 | return; |
| 58 | } |
| 59 | else if(matC.num_dims!=2) |
| 60 | { |
| 61 | std::cout<<"the dimension of C is wrong! C dims: "<< matC.num_dims <<std::endl; |
| 62 | return; |
| 63 | } |
| 64 | #endif |
| 65 | |
| 66 | size_l m = matA.dimensions[0]; |
| 67 | size_l n = matB.dimensions[1]; |
| 68 | size_l k = matA.dimensions[1]; |
| 69 | //TODO: this all convert to double, should change |
| 70 | if(transb == CUBLAS_OP_T){ |
| 71 | n = matB.dimensions[0]; |
| 72 | } |
| 73 | if(transa == CUBLAS_OP_T){ |
| 74 | m = matA.dimensions[1]; |
| 75 | k = matA.dimensions[0]; |
| 76 | } |
| 77 | CHECK_CUBLAS(cublasDgemm(cublas_H.cublas_handle, |
| 78 | transa, transb, |
| 79 | m, n, k, |
| 80 | &alpha, |
| 81 | matA.vals, matA.dimensions[0], |
| 82 | matB.vals, matB.dimensions[0], |
| 83 | &beta, |
| 84 | matC.vals, matC.dimensions[0])); |
| 85 | |
| 86 | return; |
| 87 | } |
| 88 | |
| 89 | // dnmat1[i] <-- op(dnmat2[i]) * op(dnmat3[i]), i = 1 ... batch_size |
| 90 | // op() is either identity or transpose |
no outgoing calls
no test coverage detected