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

Function main

src/samples/example_stpsv.c:65–162  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 4

clblasSetupFunction · 0.85
clblasStpsvFunction · 0.85
clblasTeardownFunction · 0.85
printResultFunction · 0.70

Tested by

no test coverage detected