Results 1 to 3 of 3

Thread: HelloWorld errors

  1. #1
    Newbie
    Join Date
    Jun 2014
    Posts
    2

    HelloWorld errors

    Hello everyone, my name is Dani and here is my first OpenCL program.
    I have visual studio 2010, installed Instel SDK for Visual Studio and nvidia toolkit v3.2

    After debugging i have some errors and warning:

    Error 1 error CL: Failed to create context for Intel OpenCL Intel CPU device... C:\Users\Usuario\Desktop\OpenCL\HW\OpenCLProject1\ OpenCLProject1\hello.cl 1 1 OpenCLProject1

    Error 2 error MSB3721: El comando ""C:\Program Files (x86)\Intel\OpenCL SDK\3.0\bin\x86\ioc32.exe" -cmd=build -input="C:\Users\Usuario\Desktop\OpenCL\HW\OpenCLPr oject1\OpenCLProject1\hello.cl" -output="Release\hello.out" -VS -device=CPU -simd=default -bo=" ""return the code -1. C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\BuildCustomizatio ns\IntelOpenCL.targets 70 6 OpenCLProject1





    Here the code from hello.cpp

    #include <stdio.h>
    #include <stdlib.h>

    #ifdef __APPLE__
    #include <OpenCL/opencl.h>
    #else
    #include <CL/cl.h>
    #endif

    #define MEM_SIZE (128)
    #define MAX_SOURCE_SIZE (0x100000)

    int main()
    {
    cl_device_id device_id = NULL;
    cl_context context = NULL;
    cl_command_queue command_queue = NULL;
    cl_mem memobj = NULL;
    cl_program program = NULL;
    cl_kernel kernel = NULL;
    cl_platform_id platform_id = NULL;
    cl_uint ret_num_devices;
    cl_uint ret_num_platforms;
    cl_int ret;

    char string[MEM_SIZE];

    FILE *fp;
    char fileName[] = "./hello.cl";
    char *source_str;
    size_t source_size;

    /* Load the source code containing the kernel*/
    fp = fopen(fileName, "r");
    if (!fp) {
    fprintf(stderr, "Failed to load kernel.\n");
    exit(1);
    }
    source_str = (char*)malloc(MAX_SOURCE_SIZE);
    source_size = fread(source_str, 1, MAX_SOURCE_SIZE, fp);
    fclose(fp);

    /* Get Platform and Device Info */
    ret = clGetPlatformIDs(1, &platform_id, &ret_num_platforms);
    ret = clGetDeviceIDs(platform_id, CL_DEVICE_TYPE_DEFAULT, 1, &device_id, &ret_num_devices);

    /* Create OpenCL context */
    context = clCreateContext(NULL, 1, &device_id, NULL, NULL, &ret);

    /* Create Command Queue */
    command_queue = clCreateCommandQueue(context, device_id, 0, &ret);

    /* Create Memory Buffer */
    memobj = clCreateBuffer(context, CL_MEM_READ_WRITE,MEM_SIZE * sizeof(char), NULL, &ret);

    /* Create Kernel Program from the source */
    program = clCreateProgramWithSource(context, 1, (const char **)&source_str,
    (const size_t *)&source_size, &ret);

    /* Build Kernel Program */
    ret = clBuildProgram(program, 1, &device_id, NULL, NULL, NULL);

    /* Create OpenCL Kernel */
    kernel = clCreateKernel(program, "hello", &ret);

    /* Set OpenCL Kernel Parameters */
    ret = clSetKernelArg(kernel, 0, sizeof(cl_mem), (void *)&memobj);

    /* Execute OpenCL Kernel */
    ret = clEnqueueTask(command_queue, kernel, 0, NULL,NULL);

    /* Copy results from the memory buffer */
    ret = clEnqueueReadBuffer(command_queue, memobj, CL_TRUE, 0,
    MEM_SIZE * sizeof(char),string, 0, NULL, NULL);

    /* Display Result */
    puts(string);

    /* Finalization */
    ret = clFlush(command_queue);
    ret = clFinish(command_queue);
    ret = clReleaseKernel(kernel);
    ret = clReleaseProgram(program);
    ret = clReleaseMemObject(memobj);
    ret = clReleaseCommandQueue(command_queue);
    ret = clReleaseContext(context);

    free(source_str);

    return 0;
    }


    and here from hello.cl


    // TODO: Add OpenCL kernel code here.
    __kernel void hello(__global char* string)
    {
    string[0] = 'H';
    string[1] = 'e';
    string[2] = 'l';
    string[3] = 'l';
    string[4] = 'o';
    string[5] = ',';
    string[6] = ' ';
    string[7] = 'W';
    string[8] = 'o';
    string[9] = 'r';
    string[10] = 'l';
    string[11] = 'd';
    string[12] = '!';
    string[13] = '\0';
    }


    Some idea?

  2. #2
    Junior Member
    Join Date
    Oct 2011
    Posts
    25
    How do you obtain the error text about context creation? I don't see you checking the value of "ret" anywhere.

  3. #3
    Newbie
    Join Date
    Jun 2014
    Posts
    2
    I fix both errors,Im gonna explain what i had to do.

    First, I removed from "OpenCL Files" in visual studio, my .cl file.

    Then i updated the dll package of visual studio

    Finally i configured properly the c/c++ and the linker, inside the solution properties .

    I had some problems with x64 and x32 compatibility in visual studio, i had to fix it too.


    Thanks u all for the attention, greetings!

Posting Permissions

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