cooler test
This commit is contained in:
parent
4ce1d245e3
commit
68bea8a225
@ -13,7 +13,7 @@
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#define MSIZE 64
|
||||
#define MSIZE 32
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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
|
||||
int main()
|
||||
{
|
||||
@ -76,19 +102,9 @@ int main()
|
||||
float matrixA[MSIZE][MSIZE] = {0};
|
||||
float matrixB[MSIZE][MSIZE] = {0};
|
||||
float matrixC[MSIZE][MSIZE] = {0};
|
||||
// fill an identity matrix
|
||||
for (int y = 0; y < MSIZE; y++) {
|
||||
matrixA[y][y] = 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;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
fill_garbage((float *)matrixA, MSIZE, MSIZE);
|
||||
matrixB[0][0] = 1.0;
|
||||
|
||||
// create the tensors, tensors are just arrays, in the shader we will have
|
||||
// to describe how it translates to matrices
|
||||
@ -164,13 +180,12 @@ int main()
|
||||
printf("\n");
|
||||
|
||||
// print the resulting matrix
|
||||
for (int y = 0; y < MSIZE; y++) {
|
||||
for (int x = 0; x < MSIZE; x++) {
|
||||
float elem = tensorC->vector<float>().at(y * MSIZE + x);
|
||||
printf("%.1f ", elem);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
printf("matrixA:\n");
|
||||
print_matrix(&tensorA->vector<float>()[0], MSIZE, MSIZE);
|
||||
printf("matrixB:\n");
|
||||
print_matrix(&tensorB->vector<float>()[0], MSIZE, MSIZE);
|
||||
printf("matrixC:\n");
|
||||
print_matrix(&tensorC->vector<float>()[0], MSIZE, MSIZE);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user