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

Function main

src/samples/example_stpmv.c:61–160  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 4

clblasSetupFunction · 0.85
clblasStpmvFunction · 0.85
clblasTeardownFunction · 0.85
printResultFunction · 0.70

Tested by

no test coverage detected