Skip to content
Snippets Groups Projects
Commit a5ac493b authored by Prakalp Srivastava's avatar Prakalp Srivastava
Browse files

Preparing test case for GPU

parent c500ad88
No related branches found
No related tags found
No related merge requests found
......@@ -27,4 +27,4 @@ $(HOST:%=%.bin):%.bin:%.c
$(LLVM_CC) -O3 -lOpenCL -I /usr/local/cuda/include $< -o $@
clean :
rm -f *.ll *.bc *.s *.bin
rm -f $(HOST).ll $(KERNELS).ll *.bc *.s *.bin
......@@ -109,52 +109,9 @@ int checkResults(float* A, float* B, float* C) {
return 1; // Success
}
// Main
int main(int argc, char** argv) {
// seed for rand()
srand(2006);
// Allocate host memory for matrices A and B
unsigned int size_A = WA * HA;
unsigned int bytes_A = sizeof(float) * size_A;
float* h_A = (float*) malloc(bytes_A);
unsigned int size_B = WB * HB;
unsigned int bytes_B = sizeof(float) * size_B;
float* h_B = (float*) malloc(bytes_B);
// Initialize host memory
randomInit(h_A, size_A);
randomInit(h_B, size_B);
/*
// Print A and B
printf("\n\nMatrix A\n");
for(int i = 0; i < size_A; i++)
{
printf("%f ", h_A[i]);
if(((i + 1) % WA) == 0)
printf("\n");
}
printf("\n\nMatrix B\n");
for(int i = 0; i < size_B; i++)
{
printf("%f ", h_B[i]);
if(((i + 1) % WB) == 0)
printf("\n");
}
*/
// Allocate host memory for the result matrix C
unsigned int size_C = WC * HC;
unsigned int bytes_C = sizeof(float) * size_C;
float* h_C = (float*) malloc(bytes_C);
// Initialize OpenCL
// OpenCL specific variables
// GPU Computation of MatrixMul
void computeMatrixMul(float* h_A, unsigned bytes_A, float* h_B, unsigned bytes_B, float* h_C, unsigned bytes_C) {
// OpenCL specific variables
cl_context clGPUContext;
cl_command_queue clCommandQue;
cl_program clProgram;
......@@ -291,16 +248,7 @@ int main(int argc, char** argv) {
}
printf("\n");
*/
if(checkResults(h_A, h_B, h_C))
printf("\nPass!\n");
else
printf("\nFailed!\n");
printf("\nDone!\n");
// Deallocate memory
free(h_A);
free(h_B);
free(h_C);
clReleaseMemObject(d_A);
clReleaseMemObject(d_C);
......@@ -315,3 +263,61 @@ int main(int argc, char** argv) {
}
// Main
int main(int argc, char** argv) {
// seed for rand()
srand(2006);
// Allocate host memory for matrices A and B
unsigned int size_A = WA * HA;
unsigned int bytes_A = sizeof(float) * size_A;
float* h_A = (float*) malloc(bytes_A);
unsigned int size_B = WB * HB;
unsigned int bytes_B = sizeof(float) * size_B;
float* h_B = (float*) malloc(bytes_B);
// Initialize host memory
randomInit(h_A, size_A);
randomInit(h_B, size_B);
/*
// Print A and B
printf("\n\nMatrix A\n");
for(int i = 0; i < size_A; i++)
{
printf("%f ", h_A[i]);
if(((i + 1) % WA) == 0)
printf("\n");
}
printf("\n\nMatrix B\n");
for(int i = 0; i < size_B; i++)
{
printf("%f ", h_B[i]);
if(((i + 1) % WB) == 0)
printf("\n");
}
*/
// Allocate host memory for the result matrix C
unsigned int size_C = WC * HC;
unsigned int bytes_C = sizeof(float) * size_C;
float* h_C = (float*) malloc(bytes_C);
// Compute using OpenCL
computeMatrixMul(h_A, bytes_A, h_B, bytes_B, h_C, bytes_C);
if(checkResults(h_A, h_B, h_C))
printf("\nPass!\n");
else
printf("\nFailed!\n");
printf("\nDone!\n");
// Deallocate memory
free(h_A);
free(h_B);
free(h_C);
}
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment