summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Stellard <thomas.stellard@amd.com>2012-02-08 16:51:59 -0500
committerTom Stellard <thomas.stellard@amd.com>2012-02-08 16:51:59 -0500
commita9836d7e0b4a34297c61f6a1fb5b49dbe4514869 (patch)
treeadf9076c8e5106cb1d285b0adb14a06c91770f51
parentbdf1e3e105eb27793641d65914761da0ae139cb0 (diff)
Create context and command queue
-rw-r--r--hello_world.c37
1 files changed, 35 insertions, 2 deletions
diff --git a/hello_world.c b/hello_world.c
index 1799f77..a6624b4 100644
--- a/hello_world.c
+++ b/hello_world.c
@@ -9,9 +9,13 @@ const char * err_string(cl_int error)
{
switch(error) {
+ CASE_ERR(CL_DEVICE_NOT_AVAILABLE);
CASE_ERR(CL_DEVICE_NOT_FOUND);
+ CASE_ERR(CL_INVALID_DEVICE);
CASE_ERR(CL_INVALID_DEVICE_TYPE);
+ CASE_ERR(CL_INVALID_OPERATION);
CASE_ERR(CL_INVALID_PLATFORM);
+ CASE_ERR(CL_INVALID_PROPERTY);
CASE_ERR(CL_INVALID_VALUE);
CASE_ERR(CL_OUT_OF_HOST_MEMORY);
CASE_ERR(CL_OUT_OF_RESOURCES);
@@ -30,6 +34,10 @@ int main(int argc, char ** argv)
cl_uint total_gpu_devices;
cl_device_id device_id;
+ cl_context context;
+
+ cl_command_queue command_queue;
+
error = clGetPlatformIDs(
1, /* Max number of platform IDs to return */
&platform_id, /* Pointer to platform_id */
@@ -41,7 +49,7 @@ int main(int argc, char ** argv)
return EXIT_FAILURE;
}
- fprintf(stderr, "There are %u platforms\n", total_platforms);
+ fprintf(stderr, "There are %u platforms.\n", total_platforms);
@@ -56,7 +64,32 @@ int main(int argc, char ** argv)
return EXIT_FAILURE;
}
- fprintf(stderr, "There are %u GPU devices\n", total_gpu_devices);
+ fprintf(stderr, "There are %u GPU devices.\n", total_gpu_devices);
+
+ context = clCreateContext(NULL, /* Properties */
+ 1, /* Number of devices */
+ &device_id, /* Device pointer */
+ NULL, /* Callback for reporting errors */
+ NULL, /* User data to pass to error callback */
+ &error); /* Error code */
+
+ if (error != CL_SUCCESS) {
+ fprintf(stderr, "clCreateContext() failed: %s\n", err_string(error));
+ return EXIT_FAILURE;
+ }
+
+ fprintf(stderr, "clCreateContext() succeeded.\n");
+
+ command_queue = clCreateCommandQueue(context,
+ device_id,
+ 0, /* Command queue properties */
+ &error); /* Error code */
+
+ if (error != CL_SUCCESS) {
+ fprintf(stderr, "clCreateCommandQueue() failed: %s\n", err_string(error));
+ return EXIT_FAILURE;
+ }
+ fprintf(stderr, "clCreateCommandQueue() succeeded.\n");
return EXIT_SUCCESS;
}