Page 2 of 2 FirstFirst 12
Results 11 to 16 of 16

Thread: passing an array of char* to kernel function

  1. #11
    Member
    Join Date
    Oct 2010
    Location
    Vancouver, Canada
    Posts
    66

    Re: passing an array of char* to kernel function

    Quote Originally Posted by naroqueen
    I don't know how to thank you Andrew for the detailed explanation... this made things much more clear.... by the way I tried implementing your idea of the character buffer and working on indices instead of pointers... it's now working...
    Also I guess I'll stick to your advice David, of practicing C first... and I'd appreciate any advice of how to improve my self in C and OpenCl...
    Thanks again.
    Glad I could help.

    There are lots of good books on C -- I'm sure you can find one with good reviews on Amazon. Even if you're a C expert though, I would still recommend this general implementation pattern:

    • implement in C[/*:m:3kysdict]
    • test/debug[/*:m:3kysdict]
    • minimal conversion to OpenCL C[/*:m:3kysdict]
    • test/debug on CPU device where you can debug and/or printf[/*:m:3kysdict]
    • test on GPU device[/*:m:3kysdict]
    • take advantage of OpenCL C extensions and built-in functions to optimize incrementally[/*:m:3kysdict]
    • test/debug on CPU[/*:m:3kysdict]
    • test on GPU device[/*:m:3kysdict]
    • profile and use this to inform next incremental optimization[/*:m:3kysdict]


    It isn't too hard to build your application so that your enqueuing of kernels can be easily replaced by normal host function calls. In fact, as an extra incremental step, on most CPU devices you can enqueue your host function as a native kernel so that it still executes as part of your task graph.

    It gets a bit more challenging when you start into data parallelism, i.e. using multiple work-items. Even there though you can usually start by creating it as 1 work-item that you enqueue from a loop. For this the OpenCL 1.1 feature of being able to provide work-item id offsets is very useful (in 1.0 you have to pass in and use the offsets manually).

    The basic philosophy is to always have something working, and making small changes at a time so the problems are easier to figure out. Its important to have an idea of where you're trying to go (i.e. asynchronous optimized data-parallel tasks in a graph that runs parallel with your host code) so that you're taking steps in the right direction to get there, but small steps are much more manageable and it avoids the rather depressing feeling that nothing ever seems to be working. Using a version control system is extremely useful so that you keep a history of each incremental step of your process, along with an informative comment on each version that you put in your repository.

  2. #12
    Junior Member
    Join Date
    Oct 2010
    Posts
    26

    Re: passing an array of char* to kernel function

    Thanks very much for the valuable advice

  3. #13
    Junior Member
    Join Date
    Oct 2010
    Posts
    26

    Re: passing an array of char* to kernel function

    test/debug on CPU device where you can debug and/or printf
    Hi Andrew I know it has been a long time since I sent my last message in this thread but I have a small question related to your last message that I'd be grateful if you could answer...

    I need to test my OpenCL code on the CPU but I'm not able to make it :s
    here's my code but it always prints "Invalid Context" and the returned context address is always zero...
    I'm not sure if there's something wrong in my code or if I have to do another proc to run opencl on CPU!

    Code :
    cl_platform_id *platforms=new cl_platform_id();
    	cl_uint *num_platforms =new cl_uint();			
    	err=(cl_int *)clGetPlatformIDs(3,platforms, num_platforms);
     
     
    	cl_context_properties  properties[]= { CL_CONTEXT_PLATFORM, (cl_context_properties)platforms[0], 0};
    	hContext = clCreateContextFromType(properties, CL_DEVICE_TYPE_CPU,
    		0, 0, err);
    	if(err==CL_SUCCESS)
    		cout<<"context created successfully!"<<endl;
    	if(err==(cl_int *)CL_DEVICE_NOT_FOUND)
    		cout<<"no device of this type was found!";
     
     
    	size_t nContextDescriptorSize;
    	clGetContextInfo(hContext, CL_CONTEXT_DEVICES,
    		0, 0, &nContextDescriptorSize);
     description (the last paramter is output)
    	cl_device_id * aDevices = (cl_device_id *) malloc(nContextDescriptorSize);
    	err=(cl_int * )clGetContextInfo(hContext, CL_CONTEXT_DEVICES,
    		nContextDescriptorSize, aDevices, 0);
    	if(err==CL_SUCCESS)
    		cout<<"GetContextInfo succeeded!"<<endl;
    	if(err==(cl_int *) CL_INVALID_CONTEXT)
    		cout<<"invalid context!"<<endl;

  4. #14
    Member
    Join Date
    Oct 2010
    Location
    Vancouver, Canada
    Posts
    66

    Re: passing an array of char* to kernel function

    Quote Originally Posted by naroqueen
    Code :
    	if(err==(cl_int *)CL_DEVICE_NOT_FOUND)
    		cout<<"no device of this type was found!";
     
     
    	if(err==(cl_int *) CL_INVALID_CONTEXT)
    		cout<<"invalid context!"<<endl;
    I don't know if this is related to the problem you're having, but you're doing something strange with your error codes. Why have you declared err as a (cl_int*)? It should just be a cl_int. The call to clCreateContextFromType should have a last parameter of "&err".

    I'm guessing you're actually getting a CL_DEVICE_NOT_FOUND, but not interpreting the error code correctly. Some implementations don't have a CPU device, unfortunately.

  5. #15
    Junior Member
    Join Date
    Oct 2010
    Posts
    26

    Re: passing an array of char* to kernel function

    Some implementations don't have a CPU device, unfortunately.
    Thanks very much for the reply but if it is not supported, how can I debug my opencl code on cpu? is there any way to do this with my Nvidia drive or the only way is to install ATI drive which enables running opencl code on cpu?

    Also I have a small question if you please; how can I run on 1 work item in a loop? :-
    Even there though you can usually start by creating it as 1 work-item that you enqueue from a loop.
    sorry for my many questions and thanks a lot for you cooperation!

  6. #16
    Member
    Join Date
    Oct 2010
    Location
    Vancouver, Canada
    Posts
    66

    Re: passing an array of char* to kernel function

    Yes, you can try installing the AMD and now Intel implementations. The committee has defined an ICD model that all vendors are adhering to so that you can have one system with multiple implementations installed, and Programs which use the clPLatform APIs to choose between at runtime.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Replies: 3
    Last Post: 01-30-2013, 03:34 AM
  2. Replies: 10
    Last Post: 11-08-2011, 06:28 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
  •