|
|
@ -13,7 +13,7 @@ |
|
|
|
|
|
|
|
|
|
|
|
#include <unistd.h> |
|
|
|
#include <unistd.h> |
|
|
|
|
|
|
|
|
|
|
|
#define MSIZE 64 |
|
|
|
#define MSIZE 32 |
|
|
|
|
|
|
|
|
|
|
|
static std::vector<uint32_t> compile_shader(const std::string &source) |
|
|
|
static std::vector<uint32_t> compile_shader(const std::string &source) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -61,6 +61,32 @@ std::string replacewith(const char *needle, T val, std::string str) |
|
|
|
return str; |
|
|
|
return str; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void print_matrix(float m[], size_t w, size_t h) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
for (size_t y = 0; y < h; y++) { |
|
|
|
|
|
|
|
for (size_t x = 0; x < w; x++) { |
|
|
|
|
|
|
|
printf("%.1f ", m[y * w + x]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
printf("\n"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void fill_identity(float m[], size_t w, size_t h) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
for (size_t y = 0; y < h; y++) { |
|
|
|
|
|
|
|
m[y * w + y] = 1.0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void fill_garbage(float m[], size_t w, size_t h) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
for (size_t y = 0; y < h; y++) { |
|
|
|
|
|
|
|
for (size_t x = 0; x < w; x++) { |
|
|
|
|
|
|
|
m[y * w + x] = x * 0.74 - y * 0.22; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// compute C = A*B on the GPU
|
|
|
|
// compute C = A*B on the GPU
|
|
|
|
int main() |
|
|
|
int main() |
|
|
|
{ |
|
|
|
{ |
|
|
@ -76,19 +102,9 @@ int main() |
|
|
|
float matrixA[MSIZE][MSIZE] = {0}; |
|
|
|
float matrixA[MSIZE][MSIZE] = {0}; |
|
|
|
float matrixB[MSIZE][MSIZE] = {0}; |
|
|
|
float matrixB[MSIZE][MSIZE] = {0}; |
|
|
|
float matrixC[MSIZE][MSIZE] = {0}; |
|
|
|
float matrixC[MSIZE][MSIZE] = {0}; |
|
|
|
// fill an identity matrix
|
|
|
|
|
|
|
|
for (int y = 0; y < MSIZE; y++) { |
|
|
|
fill_garbage((float *)matrixA, MSIZE, MSIZE); |
|
|
|
matrixA[y][y] = 1.0; |
|
|
|
matrixB[0][0] = 1.0; |
|
|
|
matrixB[y][y] = 2.0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// fill a matrix with data
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
for (int y = 0; y < MSIZE; y++) { |
|
|
|
|
|
|
|
for (int x = 0; x < MSIZE; x++) { |
|
|
|
|
|
|
|
matrixB[y][x] = x * 0.74 - y * 0.22; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// create the tensors, tensors are just arrays, in the shader we will have
|
|
|
|
// create the tensors, tensors are just arrays, in the shader we will have
|
|
|
|
// to describe how it translates to matrices
|
|
|
|
// to describe how it translates to matrices
|
|
|
@ -164,13 +180,12 @@ int main() |
|
|
|
printf("\n"); |
|
|
|
printf("\n"); |
|
|
|
|
|
|
|
|
|
|
|
// print the resulting matrix
|
|
|
|
// print the resulting matrix
|
|
|
|
for (int y = 0; y < MSIZE; y++) { |
|
|
|
printf("matrixA:\n"); |
|
|
|
for (int x = 0; x < MSIZE; x++) { |
|
|
|
print_matrix(&tensorA->vector<float>()[0], MSIZE, MSIZE); |
|
|
|
float elem = tensorC->vector<float>().at(y * MSIZE + x); |
|
|
|
printf("matrixB:\n"); |
|
|
|
printf("%.1f ", elem); |
|
|
|
print_matrix(&tensorB->vector<float>()[0], MSIZE, MSIZE); |
|
|
|
} |
|
|
|
printf("matrixC:\n"); |
|
|
|
printf("\n"); |
|
|
|
print_matrix(&tensorC->vector<float>()[0], MSIZE, MSIZE); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|