diff --git a/src/wrapper/wrap_cl.hpp b/src/wrapper/wrap_cl.hpp
index 02ba206db8d755afbded253380681bc48a7ee306..f17ee69c92a7ab746ae031b60d95a6771293cf17 100644
--- a/src/wrapper/wrap_cl.hpp
+++ b/src/wrapper/wrap_cl.hpp
@@ -852,7 +852,7 @@ namespace pyopencl
     {
       cl_int status_code;
       status_code = clGetDeviceIDs(m_platform, devtype, 0, 0, &num_devices);
-      if (status_code != CL_DEVICE_NOT_FOUND)
+      if (status_code == CL_DEVICE_NOT_FOUND)
         num_devices = 0;
       else if (status_code != CL_SUCCESS) \
         throw pyopencl::error("clGetDeviceIDs", status_code);