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

Function main

src/samples/example_saxpy.c:67–158  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

65}
66
67int
68main(void)
69{
70 cl_int err;
71 cl_platform_id platform = 0;
72 cl_device_id device = 0;
73 cl_context_properties props[3] = { CL_CONTEXT_PLATFORM, 0, 0 };
74 cl_context ctx = 0;
75 cl_command_queue queue = 0;
76 cl_mem bufX, bufY;
77 cl_event event = NULL;
78 int ret = 0;
79 int lenX = 1 + (N-1)*abs(incx);
80 int lenY = 1 + (N-1)*abs(incy);
81
82 /* Setup OpenCL environment. */
83 err = clGetPlatformIDs(1, &platform, NULL);
84 if (err != CL_SUCCESS) {
85 printf( "clGetPlatformIDs() failed with %d\n", err );
86 return 1;
87 }
88
89 err = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 1, &device, NULL);
90 if (err != CL_SUCCESS) {
91 printf( "clGetDeviceIDs() failed with %d\n", err );
92 return 1;
93 }
94
95 props[1] = (cl_context_properties)platform;
96 ctx = clCreateContext(props, 1, &device, NULL, NULL, &err);
97 if (err != CL_SUCCESS) {
98 printf( "clCreateContext() failed with %d\n", err );
99 return 1;
100 }
101
102 queue = clCreateCommandQueue(ctx, device, 0, &err);
103 if (err != CL_SUCCESS) {
104 printf( "clCreateCommandQueue() failed with %d\n", err );
105 clReleaseContext(ctx);
106 return 1;
107 }
108
109 /* Setup clblas. */
110 err = clblasSetup();
111 if (err != CL_SUCCESS) {
112 printf("clblasSetup() failed with %d\n", err);
113 clReleaseCommandQueue(queue);
114 clReleaseContext(ctx);
115 return 1;
116 }
117
118 /* Prepare OpenCL memory objects and place matrices inside them. */
119 bufX = clCreateBuffer(ctx, CL_MEM_READ_ONLY, (lenX*sizeof(cl_float)), NULL, &err);
120 bufY = clCreateBuffer(ctx, CL_MEM_READ_WRITE, (lenY*sizeof(cl_float)), NULL, &err);
121
122 err = clEnqueueWriteBuffer(queue, bufX, CL_TRUE, 0, (lenX*sizeof(cl_float)), X, 0, NULL, NULL);
123 err = clEnqueueWriteBuffer(queue, bufY, CL_TRUE, 0, (lenY*sizeof(cl_float)), Y, 0, NULL, NULL);
124

Callers

nothing calls this directly

Calls 4

clblasSetupFunction · 0.85
clblasSaxpyFunction · 0.85
clblasTeardownFunction · 0.85
printResultFunction · 0.70

Tested by

no test coverage detected