title: PyOpenCL on Linux Mint: PLATFORM_NOT_FOUND_KHR
body: <p>I've been trying to get <a href="https://mathema.tician.de/software/pyopencl/" rel="nofollow noreferrer">PyOpenCL</a> and <a href="https://mathema.tician.de/software/pycuda/" rel="nofollow noreferrer">PyCUDA</a> running on a Linux Mint machine. I have things installed but the demo scripts fail with the error:</p>
  
  <pre><code>pyopencl.cffi_cl.LogicError: clgetplatformids failed: PLATFORM_NOT_FOUND_KHR
  </code></pre>
  
  <h3>Configuration</h3>
  
  <p><code>$ uname -a &amp;&amp; cat /etc/lsb-release &amp;&amp; lspci | grep NV</code></p>
  
  <pre><code>    Linux 3.13.0-24-generic #47-Ubuntu SMP Fri May 2 23:30:00 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
      DISTRIB_DESCRIPTION="Linux Mint 17.3 Rosa"
      01:00.0 VGA compatible controller: NVIDIA Corporation GK208 [GeForce GT 730] (rev a1)
  </code></pre>
  
  <p>Relevant installed packages:</p>
  
  <pre><code>libcuda1-352-updates
  libcudart5.5:amd64
  nvidia-352-updates
  nvidia-352-updates-dev
  nvidia-cuda-dev
  nvidia-cuda-toolkit
  nvidia-opencl-icd-352-updates
  nvidia-profiler
  nvidia-settings
  ocl-icd-libopencl1:amd64
  ocl-icd-opencl-dev:amd64
  opencl-headers
  python-pycuda
  python-pyopencl
  python3-pycuda
  python3-pyopencl
  </code></pre>
  
  <h3>Research</h3>
  
  <p><a href="http://mhr3.blogspot.co.uk/2013/06/opencl-on-ubuntu-1304.html" rel="nofollow noreferrer">This post</a> describes a scenario in which the package-manager installed opencl/cuda implementation don't set up some simlinks correctly. That issue doesn't seem to be present on my system.</p>
  
  <p>There was a version number mismatch between the graphics drivers (were nvidia-340) and the nvidia-opencl package (352). I update the graphics drivers to <code>nvidia-352-updates-dev</code> but the issue remains.</p>
  
  <p>There is a <a href="https://bugs.archlinux.org/task/39203" rel="nofollow noreferrer">bug in Arch linux</a> that seems to revolve around the necessary device files not being created. However, I've verified that the <code>/dev/nvidia0</code> and <code>/dev/nvidiactl</code> exist and have permissions 666, so they should be accessible.</p>
  
  <p><a href="https://stackoverflow.com/questions/29315603/opencl-clgetplatformids-error-1001">Another Stackoverflow post</a> suggests running the demos as root. I have tried this and the behavior does not change.</p>
  
  <p><a href="http://kratos-wiki.cimne.upc.edu/index.php/How_to_set_up_OpenCL" rel="nofollow noreferrer">Older installation instructions</a> for cuda/opencl say to download drivers directly from the NVidia website. I'm not sure this still applies, so I'm holding off on that for now since there seem to be plenty of relevant packages in the respositories.</p>
  
  <p><a href="https://community.amd.com/thread/130241" rel="nofollow noreferrer">The same error, but for an ATI card on a different linux system</a>, was resolved by putting proper files in <code>/usr/lib/OpenCL/vendors</code>. That path isn't used on my system, However, I do have <code>/etc/OpenCL/vendors/nvidia.icd</code> which contains the line <code>libnvidia-opencl.so.1</code>, suggesting my issue is dissimilar.</p>
  
  <p><a href="https://devtalk.nvidia.com/default/topic/457128/cuda-programming-and-performance/gpu-not-found-when-no-display-device-connected/" rel="nofollow noreferrer">This error has been observed on OSX</a>, but for unrelated reasons. <a href="https://stackoverflow.com/questions/14719065/pycuda-multiprocessing-issue-on-os-x-10-8">Similar error messages for PyCUDA</a> also appear to be unrelated.</p>
  
  <p><a href="https://devtalk.nvidia.com/default/topic/465288/problem-running-opencl-programs/" rel="nofollow noreferrer">This error can occur under remote access since the device files are not initialized if X is not loaded</a>. However, I'm testing this in a desktop environment. Furthermore, I've run the manual commands suggested in that thread just to be sure, and they are redundant since the relevant /dev entries already exist.</p>
  
  <p>There is a note <a href="http://simoncblyth.bitbucket.org/env/notes/chroma/chroma_tests/chroma_cube/" rel="nofollow noreferrer">here</a> about simply running a command a few times to get around some sort temporary glitch. That doesn't seem to help.</p>
  
  <p><a href="https://nonzen.in/2011/10/16/copperhead.html" rel="nofollow noreferrer">This post</a> describes how the similar <code>cuInit failed: no device</code> CUDA error was caused by not having the user in the <code>video</code> group. To check, I ran <code>usermod -a -G video $USER</code>, but it did not resolve my issue.</p>
  
  <p><a href="https://lists.tiker.net/pipermail/pycuda/2010-March/002257.html" rel="nofollow noreferrer">In the past, routine updates have broken CUDA support</a>. I have not taken the time to explore every permutation of package version numbers, and it's possible that downgrading some packages may change the situation. However, without further intuition about the source of the issue, I'm not going to invest time in doing that since I don't know whether it will work. </p>
  
  <p>The <a href="https://lists.tiker.net/pipermail/pycuda/2010-March/002257.html" rel="nofollow noreferrer">most common google search result</a> for this error, <a href="http://pycuda.tiker.narkive.com/B98ia6oF/runtimeerror-cuinit-failed-no-device" rel="nofollow noreferrer">appearing</a> <a href="http://osdir.com/ml/python-cuda/2010-03/msg00101.html" rel="nofollow noreferrer">four</a> <a href="https://www.mail-archive.com/pycuda@tiker.net/msg01069.html" rel="nofollow noreferrer">times</a> on the first pages, is a short and unresolved email thread on the PyOpenCL list. Checking the permissions bits for /dev/nvidia0 and /dev/nvidiactl is suggested. On my machine user/group/other all have read and write access to these devices, so I don't think that's the source of the trouble.</p>
  
  <p>I've also tried building and installing PyOpenCL form the latest source, rather than using the version in the repositories. This is failing at an earlier phase which suggests to me it is not building correctly.</p>
  
  <h1>Summary</h1>
  
  <p>The issue would appear to be that PyCUDA/PyOpenCL cannot locate the graphics card. There are several known issues that can cause this, but none of them seem to apply here. I'm missing something, and I'm not sure what else to do.</p>