| #include <iostream> |
| #include "../include/neuroflow/tensor.hpp" |
|
|
| using namespace neuroflow; |
|
|
| int main() { |
| std::cout << "GEMM transpose test..." << std::endl; |
| |
| |
| Tensor A({1, 64}); |
| Tensor B({64, 64}); |
| Tensor C({1, 64}); |
| |
| float* a = A.as_fp32(); |
| float* b = B.as_fp32(); |
| for (size_t i = 0; i < A.numel(); ++i) a[i] = 0.1f * i; |
| for (size_t i = 0; i < B.numel(); ++i) b[i] = 0.01f * i; |
| |
| std::cout << "A shape: [" << A.shape_[0] << ", " << A.shape_[1] << "]" << std::endl; |
| std::cout << "B shape: [" << B.shape_[0] << ", " << B.shape_[1] << "]" << std::endl; |
| std::cout << "C shape: [" << C.shape_[0] << ", " << C.shape_[1] << "]" << std::endl; |
| |
| |
| bool transA = false; |
| bool transB = true; |
| |
| size_t M = transA ? A.shape_[1] : A.shape_[0]; |
| size_t K = transA ? A.shape_[0] : A.shape_[1]; |
| size_t N = transB ? B.shape_[0] : B.shape_[1]; |
| |
| std::cout << "M=" << M << ", K=" << K << ", N=" << N << std::endl; |
| std::cout << "transA=" << transA << ", transB=" << transB << std::endl; |
| |
| std::cout << "Calling gemm..." << std::endl; |
| TensorOps::gemm(A, B, C, transA, transB); |
| |
| std::cout << "C values: "; |
| float* c = C.as_fp32(); |
| for (size_t i = 0; i < 5; ++i) std::cout << c[i] << " "; |
| std::cout << std::endl; |
| |
| std::cout << "Success!" << std::endl; |
| return 0; |
| } |
|
|