File size: 1,292 Bytes
26d5b81
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
#include "../include/neuroflow/tensor.hpp"

using namespace neuroflow;

int main() {
    std::cout << "GEMM detail test..." << std::endl;
    
    Tensor A({2, 64});  // input
    Tensor B({32, 64}); // weight
    Tensor C({2, 32});  // output
    
    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;
    
    // Fill data
    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 << "Calling gemm..." << std::endl;
    TensorOps::gemm(A, B, C);  // C = A @ B^T ?
    
    std::cout << "C numel: " << C.numel() << std::endl;
    std::cout << "C data_size: " << C.data_size_ << std::endl;
    
    float* c = C.as_fp32();
    std::cout << "First 5 C values: ";
    for (size_t i = 0; i < 5; ++i) std::cout << c[i] << " ";
    std::cout << std::endl;
    
    std::cout << "After gemm, trying to allocate new tensor..." << std::endl;
    Tensor new_t({10});
    
    std::cout << "Success!" << std::endl;
    return 0;
}