Can we run NVidai OpenCL samples on CPU (AMD/Intel) Are the Nvidia opencl samples runs on CPU?

Are the Nvidia opencl samples runs on CPU?

Can some comment pls?

Yes, you would have to change the source to look for CPU type devices though

Thanks jam for the reply.

I am working on “OclScan” sample, i have modified the sample to run on CPU. (line#57 main.cpp).

I got the below error when i am running the sample:

oclScan.exe Starting…

Allocating and initializing host arrays…
Initializing OpenCL…
Error -1001 in clGetPlatformIDs Call !!!

!!! Error # -1000 (Unspecified Error) at line 51 , in file .\src\main.cpp !!!

Exiting…

Any help is appreciated.

Let me help you because you are not loading the correct platform…

First thing is to change a bit the oclutils.h so as not search only for NVIDIA…

change in there :

extern “C” cl_int oclGetPlatformID(cl_platform_id* clSelectedPlatformID);

to

extern “C” cl_int oclGetPlatformID(cl_platform_id* clSelectedPlatformID, bool GPU=true);

Now go to oclutils.cpp to the declaration of : cl_int oclGetPlatformID(cl_platform_id* clSelectedPlatformID)

and change it to :

cl_int oclGetPlatformID(cl_platform_id* clSelectedPlatformID, bool GPU)

Now inside the function add this :

ciErrNum = clGetPlatformInfo (clPlatformIDs[i], CL_PLATFORM_NAME, 1024, &chBuffer, NULL);

                if(ciErrNum == CL_SUCCESS)

                {

                    if(strstr(chBuffer, "NVIDIA") != NULL && GPU)

                    {

                        *clSelectedPlatformID = clPlatformIDs[i];

                        break;

                    }

					if(strstr(chBuffer, "Intel") != NULL && !GPU)

                    {

                        *clSelectedPlatformID = clPlatformIDs[i];

                        break;

                    }

}

i.e we add to search for Intel, if you have an AMD processor replace Intel with AMD.

So we have hacked a bit oclutils.h and oclutils.cpp and all examples of NVIDIA will run normally.

Now in main.cpp

shrLog("Initializing OpenCL...\n");

        //Get the Intel Platform

        ciErrNum = oclGetPlatformID(&cpPlatform, false);

        oclCheckError(ciErrNum, CL_SUCCESS);

//Get a GPU device

        ciErrNum = clGetDeviceIDs(cpPlatform, CL_DEVICE_TYPE_CPU, 1, &cdDevice, NULL);

        oclCheckError(ciErrNum, CL_SUCCESS);

//Create the context

        cxGPUContext = clCreateContext(0, 1, &cdDevice, NULL, NULL, &ciErrNum);

        oclCheckError(ciErrNum, CL_SUCCESS);

//Create a command-queue

        cqCommandQueue = clCreateCommandQueue(cxGPUContext, cdDevice, 0, &ciErrNum);

        oclCheckError(ciErrNum, CL_SUCCESS);

I am not changing the variable cxGPUContext, you can change it to cxCPUContext if you like.

You are done. Enjoy :-) I see ./ so probably you are using Linux…you have to recompile oclutils.cpp a simple make clean and make again to save you from the fuss…also if your flavor of Linux has a TaskManager as Windows watch the CPU cores going all up. :-)

OpenCL is all wires in logic but it is for Software Engineers…with all respect to CUDA because I use it also but the latest is more to Software Developers.

You could just take the opencl file and write host code to run it on both and get used to creating a context with cpu devices in it.

Thanks Alexander for the inputs.

I have modified the code as you said, now i am getting DEVICE not found error:

oclScan.exe Starting…

Allocating and initializing host arrays…
Initializing OpenCL…

!!! Error # -1 (CL_DEVICE_NOT_FOUND) at line 59 , in file .\src\main.cpp !!!

Exiting…

main.cpp → line 58,59

58: ciErrNum = clGetDeviceIDs(cpPlatform, CL_DEVICE_TYPE_CPU, 1, &cdDevice, NULL);
59: oclCheckError(ciErrNum, CL_SUCCESS);

Can you help for this.

What processor do you have? Have you installed the Intel or AMD OpenCL SDK? If so which SDK?

I am using Intel-Core-2-Duo

I have installed only Nvidia OpenCL/CUDA SDK-4.1.

Can’t we run the sample using NVIDIA OPENCL SDK on CPU? Is the NVIDIA SDK does not supports CPU hardware?

No you can’t. The SDK of NVIDIA is just for the GPU. Since you have an Intel-Core-2-Duo then your only solution is to go to :

http://developer.amd.com/sdks/AMDAPPSDK/downloads/Pages/default.aspx

and install the AMD SDK for Linux. I am assuming you are on a Linux platform.

You have to replace the “Intel” in oclutils.cpp to “AMD”

specifically : if(strstr(chBuffer, “AMD”) != NULL && !GPU)

Thank you Alexander for all you support. I am able to runt the sample on CPU with AMD APP SDK.

Have a nice day.

Cool. Enjoy your time with OpenCL, it is a magnificent API.

Cheers,
Alexander.