| 81 | } |
| 82 | |
| 83 | int |
| 84 | main(void) |
| 85 | { |
| 86 | cl_int err; |
| 87 | cl_platform_id platform = 0; |
| 88 | cl_device_id device = 0; |
| 89 | cl_context_properties props[3] = { CL_CONTEXT_PLATFORM, 0, 0 }; |
| 90 | cl_context ctx = 0; |
| 91 | cl_command_queue queue = 0; |
| 92 | cl_mem bufA, bufC, bufB; |
| 93 | cl_event event = NULL; |
| 94 | int ret = 0; |
| 95 | |
| 96 | /* Setup OpenCL environment. */ |
| 97 | err = clGetPlatformIDs(1, &platform, NULL); |
| 98 | if (err != CL_SUCCESS) { |
| 99 | printf( "clGetPlatformIDs() failed with %d\n", err ); |
| 100 | return 1; |
| 101 | } |
| 102 | |
| 103 | err = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 1, &device, NULL); |
| 104 | if (err != CL_SUCCESS) { |
| 105 | printf( "clGetDeviceIDs() failed with %d\n", err ); |
| 106 | return 1; |
| 107 | } |
| 108 | |
| 109 | props[1] = (cl_context_properties)platform; |
| 110 | ctx = clCreateContext(props, 1, &device, NULL, NULL, &err); |
| 111 | if (err != CL_SUCCESS) { |
| 112 | printf( "clCreateContext() failed with %d\n", err ); |
| 113 | return 1; |
| 114 | } |
| 115 | |
| 116 | queue = clCreateCommandQueue(ctx, device, 0, &err); |
| 117 | if (err != CL_SUCCESS) { |
| 118 | printf( "clCreateCommandQueue() failed with %d\n", err ); |
| 119 | clReleaseContext(ctx); |
| 120 | return 1; |
| 121 | } |
| 122 | |
| 123 | /* Setup clblas. */ |
| 124 | err = clblasSetup(); |
| 125 | if (err != CL_SUCCESS) { |
| 126 | printf("clblasSetup() failed with %d\n", err); |
| 127 | clReleaseCommandQueue(queue); |
| 128 | clReleaseContext(ctx); |
| 129 | return 1; |
| 130 | } |
| 131 | |
| 132 | /* Prepare OpenCL memory objects and place matrices inside them. */ |
| 133 | bufA = clCreateBuffer(ctx, CL_MEM_READ_ONLY, N * K * sizeof(*A), |
| 134 | NULL, &err); |
| 135 | bufB = clCreateBuffer(ctx, CL_MEM_READ_ONLY, N * K * sizeof(*B), |
| 136 | NULL, &err); |
| 137 | bufC = clCreateBuffer(ctx, CL_MEM_READ_WRITE, N * N * sizeof(*C), |
| 138 | NULL, &err); |
| 139 | |
| 140 | if ((bufA == NULL) || (bufC == NULL) || (bufB == NULL)) |
nothing calls this directly
no test coverage detected