Results 1 to 6 of 6

Thread: unknown type name kernel in opencl

  1. #1

    unknown type name kernel in opencl

    build error
    ----build Log---
    :1:1: error: unknown type name '_kernel'
    _kernel void hello(_global float * input ,_ global float *output)
    ^
    :1:9: error: expected identifier or '('
    _kernel void hello(_global float * input ,_ global float *output)
    ^
    2 diagnostics generated.

    error: front end compiler failed build.

    i m using windows 7(64 bit )+ms visual studio 2010 on nvidia
    how this problem can be solved?????

  2. #2

    Re: unknown type name kernel in opencl

    This is my opencl code running on visual studio 2010 windows 7 64-bit pls help

    #include <stdio.h>
    #include "CL/cl.h"
    #define DATA_SIZE 10
    const char *KernelSource =
    "_kernel void hello(_global float * input ,_ global float *output)\n"\
    "{\n"\
    " size_t id =get_global_id(0);\n"\
    "output[id] =input[id]*input[id];\n"\
    "} \n"\
    "\n";

    int main(void)
    {
    cl_context context;
    cl_context_properties properties[3];
    cl_kernel kernel;
    cl_command_queue command_queue;
    cl_program program;
    cl_int err;
    cl_uint num_of_platforms=0;
    Cl_platform_d platform_id;
    cl_device_id device_id;
    cl_unit num_of_devices=0;
    cl_mem input,output;
    size_t global;

    float inputData[DATA_SIZE]={1,2,3,4,5,6,7,8,9,10};
    float results[DATA_SIZE]={0};

    int i;

    //retrieve a list of platform variable
    if(clGetPlatformIDs(1,&platform_id,&num_of_platfor ms)!=CL_SUCCESS)
    {
    printf("Unable to get platform_id\n);
    return 1;
    }

    //try to get supported GPU DEvice
    if(clGetDeviceIDs(platform_id,CL_DEVICE_TYPE_GPU,1 ,&device_id,
    &num_of_devices)!=CL_SUCCESS)
    {
    printf("unable to get device_id\n);
    return 1;
    }

    //context properties list -must be terminated with 0
    properties[0]=CL_CONTEXT_PLATFORM;
    properties[1]=(cl_context_properties) platform_id;
    properties[2]=0;

    //create a context with the GPU device
    context=clCreateContext(properties,1,&device_id,NU LL,NULL,&err);

    //create command queue using the context and device
    command_queue=clCreateCommandQueue(context,device_ id,0,&err);

    //create a program from the kernel source code
    program=clCreateProgramWithSource(context,1,(const char**)
    &KernelSource,NULL,&err);

    //compile the program
    if((clBuildProgram(program,0,NULL,NULL,NULL,NULL)! =CL_SUCCESS)
    {
    printf("Error building program \n");
    return1;
    }

    //specify which kernel from the program to execute
    kernel=clCreateKernel(program,"hello",&err);

    //create buffers for the input and output
    input=clCreateBuffer(context,CL_MEM_READ_ONLY,size of(float)*DATA_SIZE,NULL,NULL);

    output=clCreateBuffer(context,CL_MEM_WRITE_ONLY,si zeof(float)*DATA_SIZE,NULL,NULL);

    //load data into the input buffer

    clEnqueueWriteBuffer(command_queue,input,CL_TRUE,0 ,
    sizeof(float)*DATA_SIZE,inputData,0,NULL,NULL);

    //set the argument list for the kernel command
    clSetKernelArg(Kernel,0,sizeof(cl_mem),&input);
    clSetKernelArg(Kernel,1,sizeof(cl_mem),&output);
    global=DATA_SIZE;

    //enqueue the kernel command for execution
    clEnqueueNDRangeKernel(command_queue,kernel,1,NULL ,&global,NULL,0,NULL,NULL);
    clFinish(command_queue);

    //copy the results from out of the buffer
    clEnqueueReadBuffer(command_queue,output,CL_TRUE,0 ,sizeof(float)*DATA_SIZE,results,0,
    NULL,NULL);

    print the results
    printf("output:");
    for(i=0;i<DATA_SIZE;i++)
    {
    printf("%f",results[i]);
    }

    //cleanup-release OpenCL resources

    clReleaseMemObject(input);
    clReleaseMemObject(output);
    clReleaseProgram(program);
    clReleaseKernel(Kernel);
    clReleaseCommandQueue(command_queue);
    clReleaseContext(context);

    return 0;

    }

  3. #3
    Senior Member
    Join Date
    Mar 2011
    Location
    Seoul
    Posts
    118

    Re: unknown type name kernel in opencl

    It seems that you have one too few (or many) underscores in your attributes, e.g., __kernel or kernel. Please check that you use either two or no underscores first.

  4. #4

    Re: unknown type name kernel in opencl

    Quote Originally Posted by sean.settle
    It seems that you have one too few (or many) underscores in your attributes, e.g., __kernel or kernel. Please check that you use either two or no underscores first.
    thanks for reply . in my program in KernelSource string there is only one _kernel word used. and only one underscore used. please help in code where u r talking about?

  5. #5
    Senior Member
    Join Date
    Mar 2011
    Location
    Seoul
    Posts
    118

    Re: unknown type name kernel in opencl

    Change "_kernel" to "__kernel" or "kernel", and similarly for "_global".

  6. #6

    Re: unknown type name kernel in opencl

    Quote Originally Posted by sean.settle
    Change "_kernel" to "__kernel" or "kernel", and similarly for "_global".
    thanks its working.......

Similar Threads

  1. data type FILE in kernel
    By agmegharaj in forum OpenCL
    Replies: 2
    Last Post: 09-05-2011, 08:48 PM
  2. Replies: 2
    Last Post: 03-04-2010, 09:02 AM

Posting Permissions

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