MCPcopy Create free account
hub / github.com/clMathLibraries/clBLAS / main

Function main

src/samples/example_sgemm.c:91–195  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 4

clblasSetupFunction · 0.85
clblasSgemmFunction · 0.85
clblasTeardownFunction · 0.85
printResultFunction · 0.70

Tested by

no test coverage detected