dgemm.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2016 HPCC Systems®.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. // matrix-matrix multiply. alpha A B + beta C with flags to
  14. //transpose A and B. beta defaults to zero, and C to empty
  15. #include "eclblas.hpp"
  16. namespace eclblas {
  17. ECLBLAS_CALL void dgemm(bool & __isAllResult, size32_t & __lenResult,
  18. void * & __result, bool transposeA, bool transposeB,
  19. uint32_t m, uint32_t n, uint32_t k,
  20. double alpha, bool isAllA, size32_t lenA, const void* A,
  21. bool isAllB, size32_t lenB, const void* B, double beta,
  22. bool isAllC, size32_t lenC, const void* C) {
  23. typedef double __attribute__((aligned(1))) misaligned_double; // prevent gcc from assuming the data is correctly aligned.
  24. unsigned int lda = transposeA==0 ? m : k;
  25. unsigned int ldb = transposeB==0 ? k : n;
  26. unsigned int ldc = m;
  27. __isAllResult = false;
  28. __lenResult = m * n * sizeof(double);
  29. double *result = (double*) rtlMalloc(__lenResult);
  30. // populate if provided
  31. for(uint32_t i=0; i<m*n; i++) result[i] = (__lenResult==lenC) ?((misaligned_double*)C)[i] :0.0;
  32. cblas_dgemm(CblasColMajor,
  33. transposeA ? CblasTrans : CblasNoTrans,
  34. transposeB ? CblasTrans : CblasNoTrans,
  35. m, n, k, alpha,
  36. (const double *) A, lda,
  37. (const double *) B, ldb,
  38. beta, result, ldc);
  39. __result = (void *) result;
  40. }
  41. }