You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_shgemm.c 993 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <cblas.h>
  5. #include <riscv_vector.h>
  6. void print_matrix(float *C, int M, int N) {
  7. for (int i = 0; i < M; i++) {
  8. for (int j = 0; j < N; j++) {
  9. printf("%f ", C[i * N + j]);
  10. }
  11. printf("\n");
  12. }
  13. }
  14. int main() {
  15. const int M = 2, N = 2, K = 2;
  16. const float alpha = 1.0f;
  17. const float beta = 0.0f;
  18. // A[M x K], row-major
  19. hfloat16 A[4] = {1.0, 2.0,
  20. 3.0, 4.0};
  21. // B[K x N], row-major
  22. hfloat16 B[4] = {5.0, 6.0,
  23. 7.0, 8.0};
  24. // C[M x N], row-major
  25. float C[4] = {0};
  26. // Call OpenBLAS float16 GEMM
  27. cblas_shgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans,
  28. M, N, K,
  29. alpha,
  30. A, K, // lda = K
  31. B, N, // ldb = N
  32. beta,
  33. C, N); // ldc = N
  34. printf("Result C = A*B:\n");
  35. print_matrix(C, M, N);
  36. return 0;
  37. }