diff options
author | Tom Stellard <thomas.stellard@amd.com> | 2012-02-08 16:38:01 -0500 |
---|---|---|
committer | Tom Stellard <thomas.stellard@amd.com> | 2012-02-08 16:38:01 -0500 |
commit | bdf1e3e105eb27793641d65914761da0ae139cb0 (patch) | |
tree | 88556fb34699dbed7764e04bca2e526ef0e1dca3 |
Intial commit
-rw-r--r-- | hello_world.c | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/hello_world.c b/hello_world.c new file mode 100644 index 0000000..1799f77 --- /dev/null +++ b/hello_world.c @@ -0,0 +1,62 @@ +#include <stdio.h> +#include <stdlib.h> + +#include <CL/cl.h> + +#define CASE_ERR(ec) case ec: return #ec; + +const char * err_string(cl_int error) +{ + switch(error) { + + CASE_ERR(CL_DEVICE_NOT_FOUND); + CASE_ERR(CL_INVALID_DEVICE_TYPE); + CASE_ERR(CL_INVALID_PLATFORM); + CASE_ERR(CL_INVALID_VALUE); + CASE_ERR(CL_OUT_OF_HOST_MEMORY); + CASE_ERR(CL_OUT_OF_RESOURCES); + CASE_ERR(CL_SUCCESS); + + } +} + +int main(int argc, char ** argv) +{ + cl_int error; + + cl_uint total_platforms; + cl_platform_id platform_id; + + cl_uint total_gpu_devices; + cl_device_id device_id; + + error = clGetPlatformIDs( + 1, /* Max number of platform IDs to return */ + &platform_id, /* Pointer to platform_id */ + &total_platforms); /* Total number of platforms + * found on the system */ + + if (error != CL_SUCCESS) { + fprintf(stderr, "clGetPlatformIDs() failed: %s\n", err_string(error)); + return EXIT_FAILURE; + } + + fprintf(stderr, "There are %u platforms\n", total_platforms); + + + + error = clGetDeviceIDs(platform_id, + CL_DEVICE_TYPE_GPU, + 1, + &device_id, + &total_gpu_devices); + + if (error != CL_SUCCESS) { + fprintf(stderr, "clGetDeviceIDs() failed: %s\n", err_string(error)); + return EXIT_FAILURE; + } + + fprintf(stderr, "There are %u GPU devices\n", total_gpu_devices); + + return EXIT_SUCCESS; +} |