Results 1 to 2 of 2

Thread: SegFault at clGetDeviceIDs?

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Posts
    2

    SegFault at clGetDeviceIDs?

    Hi,

    I am only beginning to practice OpenCL, and am writing my first full program on my own. This is what I have so far.

    Code :
    #include <stdio.h>
    #include <stdlib.h>
    #include <CL/cl.h>
     
    main()
    {
            cl_int error = 0;
            cl_platform_id platform;
            cl_context context;
            cl_command_queue queue;
            cl_device_id* device;
            cl_uint* num_devices;
     
            cl_int num_platforms;
            char platform_name[100];
     
            // Platform
            error = clGetPlatformIDs(1, &platform, &num_platforms);
            if(error != CL_SUCCESS) { printf("Error getting platform id\n"); return 0; }
            printf("The platform address is: %p\n", platform);
            printf("The number of platforms is: %d\n", num_platforms);
     
            error = clGetPlatformInfo(platform, CL_PLATFORM_NAME, sizeof(platform_name), platform_name, NULL);
            if(error != CL_SUCCESS) { printf("Error getting platform name\n"); return 0; }
            printf("The platform name is: %s\n", platform_name);
     
            device = malloc(sizeof(cl_device_id));
    //      error = clGetDeviceIDs(platform, CL_DEVICE_TYPE_ALL, 1, device, num_devices);
            printf("Hello!\n");
            return 0;
    }

    The commented-out line,
    Code :
    error = clGetDeviceIDs(platform, CL_DEVICE_TYPE_ALL, 1, device, num_devices);
    results in a segfault error. However, the strange thing is that it is not fatal, and the line "Hello!" prints just fine as per the printf statement. Does anyone know why the segfault is happening and how I can fix it? Thank you very much!

  2. #2
    Junior Member
    Join Date
    Dec 2012
    Posts
    2

    Re: SegFault at clGetDeviceIDs?

    The problem fixed (?) itself. I decided to go ahead and finish the part of the program that I was working on, and then when I re-compiled and ran it, it would no longer segfault.

    Here is the full code, for reference.

    Code :
    #include <stdio.h>
    #include <stdlib.h>
    #include <CL/cl.h>
     
    main()
    {
            cl_int error = 0;
            cl_platform_id platform;
            cl_context context;
            cl_command_queue queue;
            cl_device_id* device;
            cl_uint* num_devices;
     
            cl_int num_platforms;
            char platform_name[100];
     
            // Platform, Devices, Context, Command Queue
            error = clGetPlatformIDs(1, &platform, &num_platforms);
            if(error != CL_SUCCESS) { printf("Error getting platform id\n"); return 0; }
            printf("The platform address is: %p\n", platform);
            printf("The number of platforms is: %d\n", num_platforms);
     
            error = clGetPlatformInfo(platform, CL_PLATFORM_NAME, sizeof(platform_name), platform_name, NULL);
            if(error != CL_SUCCESS) { printf("Error getting platform name\n"); return 0; }
            printf("The platform name is: %s\n", platform_name);
     
            device = malloc(sizeof(cl_device_id));
            error = clGetDeviceIDs(platform, CL_DEVICE_TYPE_ALL, 1, device, num_devices);
            printf("Hello!\n");
     
            context = clCreateContext(NULL, 1, device, NULL, NULL, &error);
            if(error != CL_SUCCESS) { printf("Error getting context\n"); return 0; }
     
            queue = clCreateCommandQueue(context, *device, 0, &error);
            if(error != CL_SUCCESS) { printf("Error getting queue\n"); return 0; }
     
            // TODO: Kernel
     
    return 0;
    }

Similar Threads

  1. Wrong cl_mem pointer causes segfault
    By SAdam in forum OpenCL
    Replies: 1
    Last Post: 07-12-2012, 06:01 AM
  2. Replies: 7
    Last Post: 01-12-2010, 11:14 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •