Skip to content

Conversation

ddemidov
Copy link
Contributor

With this patch, boost::compute::system::default_device() supports the following environment
variables:

  • BOOST_COMPUTE_DEFAULT_DEVICE for device name;
  • BOOST_COMPUTE_DEFAULT_PLATFORM for OpenCL platform name;
  • BOOST_COMPUTE_DEFAULT_VENDOR for device vendor name.
  1. If one or more of these variables is set, then device that satisfies all
    conditions gets selected.
  2. If such a device is unavailable, then the first available GPU is selected.
  3. If there are no GPUs in the system, then the first available CPU is selected.
  4. Otherwise, default_device() returns null device.

The hello_world example is modified to use default_device() instead of
default_gpu_device().

(edited from:
BOOST_COMPUTE_DEFAULT_DEVICE="Intel"
is much more convenient and less error prone than
BOOST_COMPUTE_DEFAULT_DEVICE="Intel(R) Core(TM) i7 CPU 920 @ 2.67GHz"
)

@kylelutz
Copy link
Collaborator

Hey Denis,

Sorry it took me so long to get around to this. I thought about it a bit and I like the idea but I have a few modifications. One problem I see is that the while the name for Intel devices contains "Intel", the name for NVIDIA GPU's don't (one of mine returns "NVS 4200M").

I think a better approach would be to add an additional environmental variable, BOOST_COMPUTE_DEFAULT_VENDOR, and then use the following procedure in default_device():

  1. If BOOST_COMPUTE_DEFAULT_DEVICE is specified, return the first device whose name matches exactly.
  2. If BOOST_COMPUTE_DEFAULT_VENDOR is specified, return the first device whose vendor's name matches exactly.
  3. Return the first GPU device found.
  4. Return the first CPU device found.

Another possibility is to have a BOOST_COMPUTE_DEFAULT_PLATFORM and then the first device on a platform with the given name would be used.

Let me know what you think.

-kyle

@ddemidov
Copy link
Contributor Author

Hello Kyle,

I like the idea about more environment variables, but I still think that specifying substrings is more convenient and could potentially save the world from repetitive strain injury :). In my example I could also specify BOOST_COMPUTE_DEFAULT_DEVICE="920", and you could shorten "NVS 4200M" to "NVS" or "4200M".

In VexCL I have a set of predefined device filters and my personal favorite is the one based on environment variables. The two variables I tend to use the most are OCL_DEVICE and OCL_PLATFORM. The platform filter is more convenient than vendor for me, because I have quite a zoo on my machine:

  Intel(R) Core(TM) i7 CPU         920  @ 2.67GHz
    CL_PLATFORM_NAME              = AMD Accelerated Parallel Processing

  Intel(R) Core(TM) i7 CPU         920  @ 2.67GHz
    CL_PLATFORM_NAME              = Intel(R) OpenCL

  Tesla K20c
    CL_PLATFORM_NAME              = NVIDIA CUDA

  GeForce 9800 GT
    CL_PLATFORM_NAME              = NVIDIA CUDA

  Tesla C2075
    CL_PLATFORM_NAME              = NVIDIA CUDA

Vendor filter would not be very useful, because Intel would give me two copies of the same CPU, and 'NVIDIA' would return the three GPUs. On the other hand OCL_PLATFORM="AMD" or "Intel" would select the right implementation for me (again, the use of shortened names saves my day). But I agree that filtering by vendor is sometimes convenient.

I'll change my patch to support the three environment variables.

Cheers,
Denis

BOOST_COMPUTE_DEFAULT_DEVICE="Intel"
is much more convenient than
BOOST_COMPUTE_DEFAULT_DEVICE="Intel(R) Core(TM) i7 CPU         920  @ 2.67GHz"
boost::compute::system::default_device() supports the following environment
variables:

BOOST_COMPUTE_DEFAULT_DEVICE   for device name
BOOST_COMPUTE_DEFAULT_PLATFORM for OpenCL platform name
BOOST_COMPUTE_DEFAULT_VENDOR   for device vendor name

If one or more of these variables is set, then device that satisfies all
conditions gets selected.
If such a device is unavailable, then the first available GPU is selected.
If there are no GPUs in the system, then the first available CPU is selected.
Otherwise, default_device() returns null device.

The hello_world example is modified to use default_device() instead of
default_gpu_device().
@ddemidov
Copy link
Contributor Author

Kyle, take a look at 160089e. Feel free to change the matches() function to only return true in case of exact match.

The device_platform() function could in principle be made a boost::compute::device method, but that creates circular dependency between device.hpp and platform.hpp.

@kylelutz
Copy link
Collaborator

Looks good!

I've squashed the last two commits together and cherry-picked it into my branch here: 8b78d41.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants