Skip to content

Instantly share code, notes, and snippets.

@patrickmmartin
Last active October 8, 2018 10:31
Show Gist options
  • Save patrickmmartin/e1313dde7b908e8d009f2a13c3cd164b to your computer and use it in GitHub Desktop.
Save patrickmmartin/e1313dde7b908e8d009f2a13c3cd164b to your computer and use it in GitHub Desktop.
pyopencl setup

pyopencl installations

Linux (Ubuntu)

basic setup

pip install pyopencl

installs OK but fails with a compilation error related to ffi.h

needed

sudo apt-get install libffi-dev

#sudo CFLAGS=-I/usr/include/libffi/include pip install pyopencl
sudo pip install pyopencl
In file included from src/c_wrapper/pyopencl_ext.h:6:0,
                 from src/c_wrapper/wrap_cl.h:12,
                 from build/temp.linux-x86_64-2.7/pyopencl._cffi.cpp:434:
src/c_wrapper/clinfo_ext.h:10:19: fatal error: CL/cl.h: No such file or directory
 #include <CL/cl.h>

but like all the others tools

fails with "could not find device" on COMPAQ_UBUNTU, DELL_LAPTOP

luxmark fails with

terminate called after throwing an instance of 'cl::Error' what(): clGetPlatformIDs

implementations are pluggable (apparently)

NVida driver has some elements sudo apt-get install nvidia-375 nvidia-375-dev nvidia-libopencl1-375 nvidia-opencl-icd-375

lots of work is done

patrick@compaq-ubuntu:~$ clinfo
Number of platforms                               0

trying Beignet (supports Kaby Lake)

https://cgit.freedesktop.org/beignet/tree/docs/Beignet.mdwn

$ sudo apt-get install cmake pkg-config python ocl-icd-dev libegl1-mesa-dev ocl-icd-opencl-dev libdrm-dev libxfixes-dev libxext-dev llvm-3.6-dev clang-3.6 libclang-3.6-dev libtinfo-dev libedit-dev zlib1g-dev

$ #or for Ubuntu 17.04

$ sudo apt-get install cmake pkg-config python ocl-icd-dev libegl1-mesa-dev ocl-icd-opencl-dev libdrm-dev libxfixes-dev libxext-dev llvm-3.7-dev clang-3.7 libclang-3.7-dev libtinfo-dev libedit-dev zlib1g-dev
$ git clone https://anongit.freedesktop.org/git/beignet.git
Cloning into 'beignet'...

> mkdir build > cd build > cmake ../ # to configure

then

make OK

make utest OK

sudo make install OK
Geez, does everyone run as root?!!

# need reboot to get working device
# then clinfo works etc.
# also 
pip install pyopencl # no longer fails

Then in utests/:

> . setenv.sh > ./utest_run 1 test fail on some numeric results

error in rossant.py - http://cyrille.rossant.net/pyopencl-on-windows-without-a-gpu/

test results are a little patchy

running the mandelbrot test:

requires additional dependency

python 2 sudo apt-get install python-imaging-tk

python 3 sudo apt-get install python-imaging-tk

Windows 10

Hardcore stylee

Python 3.6

comes with pip!

pip install pyopencl

-> needs Visual Studio 14 command line tools

-> install

-> needs cl.h

-> install Intel openCL SDK

-> in Visual Studio Native build command prompt

C:\Program Files (x86)\Microsoft Visual C++ Build Tools>set INCLUDE=%INCLUDE%;%INTELOCLSDKROOT%include

pip install pyopencl

    pyopencl._cffi.cpp
    C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -DPYGPU_PACKAGE=pyopencl -DPYGPU_PYOPENCL=1 -DPYOPENCL_USE_SHIPPED_EXT=1 -Isrc/c_wrapper/ -Ic:\users\patri\appdata\local\programs\python\python36-32\include -Ic:\users\patri\appdata\local\programs\python\python36-32\include "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\8.1\include\shared" "-IC:\Program Files (x86)\Windows Kits\8.1\include\um" "-IC:\Program Files (x86)\Windows Kits\8.1\include\winrt" "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\8.1\include\shared" "-IC:\Program Files (x86)\Windows Kits\8.1\include\um" "-IC:\Program Files (x86)\Windows Kits\8.1\include\winrt" "-IC:\Program Files (x86)\Intel\OpenCL SDK\6.3\include" /EHsc /Tpsrc/c_wrapper/wrap_cl.cpp /Fobuild\temp.win32-3.6\Release\src/c_wrapper/wrap_cl.obj -std=c++0x
    cl : Command line warning D9002 : ignoring unknown option '-std=c++0x'
    wrap_cl.cpp
    c:\users\patri\appdata\local\temp\pip-build-xp_qpsm3\pyopencl\src\c_wrapper\utils.h(226): warning C4800: 'cl_bool': forcing value to bool 'true' or 'false' (performance warning)
    src/c_wrapper/wrap_cl.cpp(58): warning C4800: 'clobj_t': forcing value to bool 'true' or 'false' (performance warning)
    src/c_wrapper/wrap_cl.cpp(100): warning C4800: 'int': forcing value to bool 'true' or 'false' (performance warning)
    c:\users\patri\appdata\local\temp\pip-build-xp_qpsm3\pyopencl\src\c_wrapper\function.h(79): fatal error C1001: An internal error has occurred in the compiler.
    (compiler file 'f:\dd\vctools\compiler\cxxfe\sl\p1\c\outdname.c', line 4869)
     To work around this problem, try simplifying or changing the program near the locations listed above.
    Please choose the Technical Support command on the Visual C++
     Help menu, or open the Technical Support help file for more information
    c:\users\patri\appdata\local\temp\pip-build-xp_qpsm3\pyopencl\src\c_wrapper\error.h(191): note: see reference to class template instantiation 'ArgPack<CLArg,_cl_device_id *const >' being compiled
    c:\users\patri\appdata\local\temp\pip-build-xp_qpsm3\pyopencl\src\c_wrapper\error.h(242): note: see reference to class template instantiation 'CLArgPack<_cl_device_id *const >' being compiled
    c:\users\patri\appdata\local\temp\pip-build-xp_qpsm3\pyopencl\src\c_wrapper\device.h(36): note: see reference to function template instantiation 'void call_guarded<const CLType&,cl_device_id>(cl_int (__stdcall *)(cl_device_id),const char *,const CLType &)' being compiled
            with
            [
                CLType=cl_device_id
            ]
    error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\cl.exe' failed with exit status 2

    ----------------------------------------
Command "c:\users\patri\appdata\local\programs\python\python36-32\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\patri\\AppData\\Local\\Temp\\pip-build-xp_qpsm3\\pyopencl\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\patri\AppData\Local\Temp\pip-4rw55nx6-record\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\patri\AppData\Local\Temp\pip-build-xp_qpsm3\pyopencl\

DOES NOT work

Using pre-built binaries

C:\Program Files (x86)\Microsoft Visual C++ Build Tools>pip install %USERPROFILE%\Downloads\pyopencl-2016.2.1+cl12-cp36-cp36m-win32.whl

-> works?

get pyopencl code

  • pyopencl works - finds openCL implementation (supplied with the Windows drivers)
  • seems to pass the tests?

MemoryError, as per

https://github.com/patrickmmartin/pyopencl/tree/fix/nvidia_mem_issue

Note, unlike SAME HARDWARE with Beignet and pyopencl!!!!

@jameswan
Copy link

jameswan commented Oct 8, 2018

Has this been solved?

I get the same error when I pip install pyopencl on Windows 64:

c:\users\james\appdata\local\temp\pip-install-5gpwnt8v\pyopencl\src\wrap_cl.hpp(31): fatal error C1083: Cannot open include file: 'CL/cl.h': No such file or directory
error: command 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.15.26726\bin\HostX64\x64\cl.exe' failed with exit status 2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment