#include #include #include #include #include #include "utils.h" #define VERBOSE #define OCL_LOCAL_SIZE 16 #define INPUT_VALUE 1 #define OUTPUT_VALUE 2 //#define VERBOSE int verify_result(unsigned int* ref, size_t n) { int ret = 0; int i; for(i=0; i < n; i++){ if(ref[i] != OUTPUT_VALUE){ ret = 1; break; } } return ret; } int seq_add(unsigned int* a, unsigned int* b, size_t n, unsigned int* out) { unsigned int i; for(i=0; iret == MCL_RET_SUCCESS) printf("Done.\n Test time: %f seconds\n", ((float)tdiff(end,start))/BILLION); else printf("Error!\n"); mcl_hdl_free(hdl); return 0; err_hdl: mcl_hdl_free(hdl); err: return -1; } #endif int main(int argc, char** argv) { unsigned int *a, *b, *out; int ret = 1; uint64_t i; mcl_banner("EXEC Vector Add Test"); parse_global_opts(argc, argv); switch(type){ case 0: #ifdef __TEST_MCL flags = MCL_TASK_CPU; #elif __TEST_OCL flags = CL_DEVICE_TYPE_CPU; #endif break; case 1: #ifdef __TEST_MCL flags = MCL_TASK_GPU; #elif __TEST_OCL flags = CL_DEVICE_TYPE_GPU; #endif break; #ifdef __TEST_MCL case 2: flags = MCL_TASK_ANY; break; #endif default: printf("Unrecognized resource type (%"PRIu64"). Aborting.\n",type); return -1; } a = (unsigned int*) malloc(size * sizeof(unsigned int)); b = (unsigned int*) malloc(size * sizeof(unsigned int)); out = (unsigned int*) malloc(size * sizeof(unsigned int)); if(!a || !b || !out){ printf("Error allocating memory. Aborting.\n"); goto err; } #ifdef __TEST_MCL mcl_init(workers, 0x0); #endif for(i=0; i < size; i++) a[i] = INPUT_VALUE; for(i=0; i < size; i++) b[i] = INPUT_VALUE; #ifdef VERBOSE printf("a = [ "); for(i=0; i < size; i++) printf("%u ", a[i]); printf("]\n"); printf("b = [ "); for(i=0; i < size; i++) printf("%u ", b[i]); printf("]\n"); #endif #ifdef __TEST_OCL printf("OpenCL test..."); ocl_add(a, b, size, out); #endif #ifdef __TEST_MCL printf("MCL test..."); mcl_add(a, b, size, out); mcl_finit(); #endif #ifdef VERBOSE printf("out = [ "); for(i=0; i < size; i++) printf("%u ", out[i]); printf("]\n"); #endif ret = verify_result(out, size); mcl_verify(ret); free(a); free(b); free(out); return ret; err: exit(EXIT_FAILURE); }