OpenCL on NVIDIA GTX670M - c++

I write a C++ application on Win64 using OpenCL. I downloaded CUDA SDK 4.2 and installed OpenCL.lib in my lib directory. In the first invocation of OpenCL:
cl_uint n = 0;
cl_int err = ::clGetPlatformIDs(0, NULL, &n);
my application goes down ( with system fatal error ). Does somebody have the same problem on NVIDIA GTX670M? How did you solve this issue?

Related

OpenCL cannot find device

I'm making a C++ program using opencl. It was really challenging to install it but I've finally managed to install it. I'm on Ubuntu 22.04, nvdia-390 GPU, intel core i7 gen3 CPU,
and my clinfo gives this output:
Number of platforms 1
Platform Name Clover
Platform Vendor Mesa
Platform Version OpenCL 1.1 Mesa 22.0.5
Platform Profile FULL_PROFILE
Platform Extensions cl_khr_icd
Platform Extensions function suffix MESA
Platform Name Clover
Number of devices 0
NULL platform behavior
clGetPlatformInfo(NULL, CL_PLATFORM_NAME, ...) Clover
clGetDeviceIDs(NULL, CL_DEVICE_TYPE_ALL, ...) No devices found in platform [Clover?]
clCreateContext(NULL, ...) [default] No devices found in platform
clCreateContextFromType(NULL, CL_DEVICE_TYPE_DEFAULT) No devices found in platform
clCreateContextFromType(NULL, CL_DEVICE_TYPE_CPU) No devices found in platform
clCreateContextFromType(NULL, CL_DEVICE_TYPE_GPU) No devices found in platform
clCreateContextFromType(NULL, CL_DEVICE_TYPE_ACCELERATOR) No devices found in platform
clCreateContextFromType(NULL, CL_DEVICE_TYPE_CUSTOM) No devices found in platform
clCreateContextFromType(NULL, CL_DEVICE_TYPE_ALL) No devices found in platform
ICD loader properties
ICD loader Name OpenCL ICD Loader
ICD loader Vendor OCL Icd free software
ICD loader Version 2.2.14
ICD loader Profile OpenCL 3.0
For some reason it cannot detect my devices. I've ran sudo apt install mesa-opencl-icd to make it finally work. When I create a C++ program to test it I get this error:
Here is my main:
#include <CL/cl.h>
#include <iostream>
int main(int argc, char* argv[])
{
cl_uint dev_cnt = 0;
cl_device_id m_device_id;
clGetPlatformIDs(0, NULL, &dev_cnt);
std::unique_ptr<cl_platform_id[]> platform_ids(new cl_platform_id[dev_cnt]);
clGetPlatformIDs(dev_cnt, platform_ids.get(), NULL);
std::cout << dev_cnt << std::endl;
int error_code = clGetDeviceIDs(platform_ids.get()[0],
CL_DEVICE_TYPE_DEFAULT,
1,
m_device_id,
NULL);
if (error_code != CL_SUCCESS)
{
std::cout << "FATAL ERROR: Failed to create a device group! Error code: " << std::endl;
return;
}
}
I get the error message as an output. I've tried changing the device type to default to no avail.
What's the problem? I don't quite remember the exact steps of how I've installed opencl but I can say it was really hard. What is missing?

No GPU Support using OpenCv 2.4.10 + Cuda 7.5 + W10

Im trying to get GPU up and running using:
OpenCv 2.4.10
Visual Studio 2013
Cuda toolkit 7.5 (cuda samples tested and running)
Windows 10 x64
Lenovo Y50 with NVIDIA GEFORCE GTX 860M
I have compiled OpenCv using CMake with WITH_CUDA=ON, and then installed the libraries by opening OpenCv.sln and built ALLBUILD and INSTALL projects.
Set my Project configuration as:
VC++ Directories
include Directories:
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.5\include
C:\OpenCv\opencv\build\install\include (Contains the compiled libraries)
C:\OpenCv\opencv\build\include
Linker-general-Additional libraries
C:\OpenCv\opencv\build\x64\vc12\lib
C:\OpenCv\opencv\build\install\x64\vc12\lib
Linker-input-Additional Depencies
opencv_calib3d2410d.lib
opencv_contrib2410d.lib
opencv_core2410d.lib
opencv_features2d2410d.lib
opencv_flann2410d.lib
opencv_gpu2410d.lib
opencv_highgui2410d.lib
opencv_imgproc2410d.lib
opencv_legacy2410d.lib
opencv_ml2410d.lib
opencv_nonfree2410d.lib
opencv_objdetect2410d.lib
opencv_ocl2410d.lib
opencv_photo2410d.lib
opencv_stitching2410d.lib
opencv_superres2410d.lib
opencv_ts2410d.lib
opencv_video2410d.lib
opencv_videostab2410d.lib
My environment variables:
Path= C:\Program Files\NVIDIA GPU Computing;Toolkit\CUDA\v7.5;C:\OpenCv\opencv\build\install\x64\vc12\bin;C:\OpenCv\opencv\build\x64\vc12\bin
Testing code:
#include "opencv2\opencv.hpp"
#include "opencv2\gpu\gpu.hpp"
using namespace cv::gpu;
using namespace std;
int main() {
{
setDevice(0);
int gpu = getCudaEnabledDeviceCount();
cout << gpu ;
system("pause");
return 0;
}
}in
But setDevice throws
no GPU support (The library is compiled without CUDA support) in
EmptyDeviceInfoFuncTable::setDevice, file
c:\builds\2_4_PackSlave-win64-vc12-shared\opencv\dynamicuda\include\opencv2/dynamiccuda/dynamicuda.hpp.
line 84
and if i comment setDevice(0) the gpu is still not detected, getCudaEnabledDeviceCount returns 0.
The problem is that Opencv 2.4.10 supports CUDA 4.2 and my video card is compatible only with CUDA 6.5 and 7.5 , I solved by installing OpenCV 3.0.0

An invalid parameter error at msvcr120.dll (Building Tesseract Lib in 64bit Windows)

I have already raised the inquiry to Tesseract Forum, but whether I can have a clue for the error, I raise the issue at this forum again. As this is my favorite forum in solving the problems.
I have a problem somehow related to the tesseract lib.
The problem is at libtiff one of the components used in leptonica library.
I followed exactly what is described here
in building libtiff for my 64bit windows.
C:\LIBTIFF\LIBTIFF> nmake /f makefile.vc
C:\LIBTIFF\LIBTIFF> cd ..\tools
C:\LIBTIFF\TOOLS> nmake /f makefile.vc
Build is ok.
Using tiff lib and I built leptonica lib and tessearact lib for 64bit windows.
Once I run my application using tesseract lib, I got error at tiff lib and the error is
"Unhandled exception at 0x00007FFA966FDD27 (msvcr120.dll) in TessarActOCR_test.exe: An invalid parameter was passed to a function that considers invalid parameters fatal."
The error is happening at lseek in the following function. The function is located in tiffio.c
static TIFF *
fopenTiff(FILE *fp,tif_win32.c
const char *modestring)
{
l_int32 fd;
PROCNAME("fopenTiff");
if (!fp)
return (TIFF *)ERROR_PTR("stream not opened", procName, NULL);
if (!modestring)
return (TIFF *)ERROR_PTR("modestring not defined", procName, NULL);
if ((fd = fileno(fp)) < 0)
return (TIFF *)ERROR_PTR("invalid file descriptor", procName, NULL);
lseek(fd, 0, SEEK_SET);
return TIFFFdOpen(fd, "TIFFstream", modestring);
}
What could be wrong with this error?
Now I solved all problems and tesseract lib is working at my 64bit pc and project. The solution for me is step by step following the discussions in this link during preparing the dependencies. Then leptonica lib is built and then link to tesseract to build tesseract lib. Now all are working well.

OpenCL not finding platforms?

I am trying to utilize the C++ API for OpenCL. I have installed my NVIDIA drivers and I have tested that I can run the simple vector addition program provided here. I can compile this program with following gcc call and the program runs without problem.
gcc main.c -o vectorAddition -l OpenCL -I/usr/local/cuda-6.5/include
However, I would very much prefer to use the C++ API as opposed the very verbose host files needed for C.
I downloaded the C++ bindings from Khronos from here and placed the cl.hpp file in the same location as my other cl.h file. The code uses some C++11 so I can compile the code with:
g++ main.cpp -o vectorAddition_cpp -std=c++11 -l OpenCL -I/usr/local/cuda-6.5/include
but when I try to run the program I get the error:
clGetPlatformIDs(-1001)
I also tried the example provided here as well which gave a more helpful error message.
No platforms found. Check OpenCL installation!
The particular code which provides this error is this:
std::vector<cl::Platform> all_platforms;
cl::Platform::get(&all_platforms);
if(all_platforms.size()==0){
std::cout<<" No platforms found. Check OpenCL installation!\n";
exit(1);
}
This seems so strange given that the C implementation runs without problem. Any insights would be sincerely appreciated.
EDIT
The C implementation actually isn't running correctly. Each addition is printed to equal zero. Checking the ret_num_platforms also returns 0. For some reason my setup is failing to find my GPU. What could I have missed? My install consists of the nvidia-340 driver and cuda-6.5 installed via apt-get and the .run file respectively.
My sincerest thanks to #pasternak for helping me troubleshoot this problem. To solve it however I ended up needing to avoid essentially all ubuntu apt-get calls for install and just use the cuda run file for the full installation. Here is what fixed the problem.
Purge existing nvidia and cuda implementations (sudo apt-get purge cuda* nvidia-*)
Download cuda-6.5 toolkit from the CUDA toolkit archive
Reboot computer
Switch to ttyl (Ctrl-Alt-F1)
Stop the X server (sudo stop lightdm)
Run the cuda run file (sh cuda_6.5.14_linux_64.run)
Select 'yes' and accept all defaults
Required reboot
Switch to ttyl, stop X server and run the cuda run file again and select 'yes' and default for everything (including the driver again)
Update PATH to include /usr/local/cuda-6.5/bin and LD_LIBRARY_PATH
to include /usr/local/cuda-6.5/lib64
Reboot again
Compile main.c program (gcc main.c -o vectorAddition -l OpenCL -I/usr/local/cuda-6.5/include)
Verify works with ./vectorAddition
C++ API
Download cl.hpp file from Khronos here noting that it is version 1.1
Place cl.hpp file in /usr/local/cuda-6.5/include/CL with other cl headers.
Compile main.cpp (g++ main.cpp -o vectorAddition_cpp -std=c++11 -l OpenCL -I/usr/local/cuda-6.5/include)
Verify it works (./vectorAddition_cpp)
All output from both programs show the correct output for addition between vectors.
I personally find it interesting the Ubuntu's nvidia drivers don't seem to play well with the cuda toolkits. Possibly just for the older versions but still very unexpected.
It is hard to say without running the specific code on your machine but looking at the difference between the example C code you said was working and the cl.hpp might give us a clue. In particular, notice that the C example uses the following line to simply read a single platform ID:
cl_platform_id platform_id = NULL;
cl_int ret = clGetPlatformIDs(1, &platform_id, &ret_num_platforms);
Notice that is passes 1 as its first argument. This assumes that at least one OpenCL platform exists and requests that the first one found is placed in platform_id. Additionally, note that even though the return code is assigned to "ret" is it not used to actually check if an error is returned.
Now if we look at the implementation of the static method used to queue the set of platforms in cl.hpp, i.e. cl::Platform::get:
static cl_int get(
VECTOR_CLASS<Platform>* platforms)
{
cl_uint n = 0;
cl_int err = ::clGetPlatformIDs(0, NULL, &n);
if (err != CL_SUCCESS) {
return detail::errHandler(err, __GET_PLATFORM_IDS_ERR);
}
cl_platform_id* ids = (cl_platform_id*) alloca(
n * sizeof(cl_platform_id));
err = ::clGetPlatformIDs(n, ids, NULL);
if (err != CL_SUCCESS) {
return detail::errHandler(err, __GET_PLATFORM_IDS_ERR);
}
platforms->assign(&ids[0], &ids[n]);
return CL_SUCCESS;
}
we see that it first calls
::clGetPlatformIDs(0, NULL, &n);
notice that the first parameter is 0, which tells the OpenCL runtime to return the number of platforms in "n". If this is successful it then goes on to request the actual "n" platform IDs.
So the difference here is that the C version is not checking that there is at least one platform and simply assuming that one exists, while the cl.hpp variant is and as such maybe it is this call that is failing.
The most likely reason for all this is that the ICD is not correctly installed. You can see this thread for an example of how to fix this issue:
ERROR: clGetPlatformIDs -1001 when running OpenCL code (Linux)
I hope this helps.

-1001 error in OpenCL with Nvidia card in Ubuntu Linux

I am trying to run this OpenCL Example in Ubuntu 10.04.
My graphics card is an NVIDIA GeForce GTX 480. I have installed the latest NVIDIA driver and CUDA toolkit manually.
The program compiles without any errors. Thus linking with libOpenCL works. The application also runs but the output is very strange (mostly zeros and some random numbers). Debugging shows that
clGetPlatformIDs(1, &platform_id, &ret_num_platforms);
returns -1001.
google and stack told me that the reason may be a missing nvidia.icd in /etc/OpenCL/vendors. It was not there so I've added /etc/OpenCL/vendors/nvidia.icd with the following line
libnvidia-opencl.so.1
I have also tried some variants (absolute paths etc). But nothing solved the problem. Right now I have no idea what else I can try. Any suggestions?
EDIT: I have installed the Intel OpenCL SDK and I have copied its icd into /etc/OpenCL/vendors and the application works fine for
clGetDeviceIDs( platform_id, CL_DEVICE_TYPE_DEFAULT, 1,
&device_id, &ret_num_devices);
For
clGetDeviceIDs( platform_id, CL_DEVICE_TYPE_GPU, 1,
&device_id, &ret_num_devices);
I get the error -1.
EDIT:
I have noticed one thing in the console when executing the application. After execution of line
cl_int ret = clGetPlatformIDs(1, &platform_id, &ret_num_platforms);
the application gives me the output
modprobe: ERROR: ../libkmod/libkmod-module.c:809 kmod_module_insert_module() could not find module by name='nvidia_331_uvm'
modprobe: ERROR: could not insert 'nvidia_331_uvm': Function not implemented
There seems to be a conflict with an older driver version since I am using 340.
cat /proc/driver/nvidia/version
NVRM version: NVIDIA UNIX x86_64 Kernel Module 340.32 Tue Aug 5 20:58:26 PDT 2014
Maybe I should try to remove Ubuntu's own NVIDIA drivers one more time and reinstall the latest manually one more time?
EDIT:
The old driver was the problem. Somehow it wasn't removed properly thus I have done it one more time with
apt-get remove nvidia-331 nvidia-opencl-icd-331 nvidia-libopencl1-331
and now it works. I hope this helps someone who has similar problems.
The above mentioned problems occurred due to a driver conflict. If you have a similar problem then read the above edits to get the solution.