Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backwards compatibility #446

Open
wants to merge 39 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
d8a73fd
* Change the OpenCL version verification system
dvdjg Mar 29, 2015
3df09fe
* Additional runtime version checks. Link time checks are not enough:…
dvdjg Mar 29, 2015
384adc2
* static cast to avoid a compiler warning.
dvdjg Mar 29, 2015
6bb7696
* Removed redundant const.
dvdjg Mar 29, 2015
a815f27
* Additional runtime version checks. Link time checks are not enough:…
dvdjg Mar 29, 2015
d46588b
* Added the version_number() function.
dvdjg Mar 29, 2015
ed7f213
* Use the context version_number() function.
dvdjg Mar 29, 2015
9078790
* Use the context version_number() function.
dvdjg Mar 29, 2015
4eb3a3b
* Changed the function name version_number() to get_version() to matc…
dvdjg Mar 29, 2015
8f20857
* Allow the automatic computation of the local work size by passing 0…
dvdjg Mar 30, 2015
b570d99
* m_version initialization was incomplete.
dvdjg Mar 30, 2015
cfa1e88
* Restored check_version() and check_device_version() for backward co…
dvdjg Mar 30, 2015
e0387db
* Compatibility with current code.
dvdjg Mar 30, 2015
6efcf0a
* enqueue_map_image() bug
dvdjg Mar 30, 2015
104e5f8
* Use of the enqueue_nd_range_kernel_async() function
dvdjg Mar 31, 2015
bffd846
* nbody.cpp - Use of:
dvdjg Mar 31, 2015
d0c4e17
* Added a default argument
dvdjg Mar 31, 2015
731c264
* Do not assume a device holds only a cl_device_id
dvdjg Mar 31, 2015
9043e98
* find_device() overload to allow partial search and min version check
dvdjg Mar 31, 2015
98210a5
* Changed the way the version is parsed. Now parses 3.01 as 301 and 1…
dvdjg Apr 1, 2015
93a5be6
* Resolve ambiguity find_device_name()
dvdjg Apr 1, 2015
ee08966
* Do not use the internal cl_event type in the functions interface
dvdjg Apr 5, 2015
d394700
* Avoid the use of min max macros in Windows
dvdjg Apr 5, 2015
3ea3157
* Use the execution_status enum
dvdjg Apr 11, 2015
6453d85
* Use const specifier
dvdjg Apr 11, 2015
07b5659
* Rename the variable future so it is not equal to the template future
dvdjg Apr 11, 2015
8cf1a0f
* Addede two utility functions:
dvdjg Apr 11, 2015
2a09905
get_type for not colliding with 'type' enum symbol
dvdjg Apr 14, 2015
8103bd3
find_device() improvements
dvdjg Apr 14, 2015
432665c
swap() facility
dvdjg Apr 14, 2015
64992da
enqueue_fill_image() fallback for pre 1.2 devices
dvdjg Apr 14, 2015
b3ce7b7
* Optional use of CL_DEVICE_TYPE_CUSTOM
dvdjg Apr 15, 2015
0d2fb59
* deleted compute::
dvdjg Apr 15, 2015
0f0b8c1
* Pre c++11 adaptation.
dvdjg Apr 15, 2015
30c69ed
* Introduced a raw version of fill image
dvdjg Apr 20, 2015
893248d
* enqueue_walk_image Default args
dvdjg Apr 20, 2015
35709b3
Adapt 1 for old compilers
dvdjg Apr 21, 2015
ef865b0
Adapt 2 for old compilers
dvdjg Apr 21, 2015
a8947bd
* Added BOOST_COMPUTE_USE_CPP11
dvdjg Apr 21, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
* Change the OpenCL version verification system
  - Removed internal funciton: bool check_version(int major, int minor) const.
  - Created function: uint_ version_number() const

  version_number function computes and caches the OpenCL device version for faster runtime checks.

* Aditional runtime version checks. Static linking checks are not enough: You can compile a funcition using a OpenCL 2.0 enabled system, but if the final device is only 1.2, only 1.2 functions must be invoked.
  • Loading branch information
dvdjg committed Mar 29, 2015
commit d8a73fdfc2fee2022ba96c7d2408765db3dcb9a4
57 changes: 27 additions & 30 deletions include/boost/compute/device.hpp
Original file line number Diff line number Diff line change
@@ -52,14 +52,14 @@ class device

/// Creates a null device object.
device()
: m_id(0)
: m_id(0), m_version(0)
{
}

/// Creates a new device object for \p id. If \p retain is \c true,
/// the reference count for the device will be incremented.
explicit device(cl_device_id id, bool retain = true)
: m_id(id)
: m_id(id), m_version(0)
{
#ifdef CL_VERSION_1_2
if(m_id && retain && is_subdevice()){
@@ -72,7 +72,7 @@ class device

/// Creates a new device object as a copy of \p other.
device(const device &other)
: m_id(other.m_id)
: m_id(other.m_id), m_version(other.m_version)
{
#ifdef CL_VERSION_1_2
if(m_id && is_subdevice()){
@@ -118,7 +118,7 @@ class device
if(m_id && is_subdevice()){
clReleaseDevice(m_id);
}
#endif
#endif // CL_VERSION_1_2

m_id = other.m_id;
other.m_id = 0;
@@ -136,7 +136,7 @@ class device
clReleaseDevice(m_id)
);
}
#endif
#endif // CL_VERSION_1_2
}

/// Returns the ID of the device.
@@ -188,6 +188,21 @@ class device
return get_info<std::string>(CL_DEVICE_VERSION);
}

/// Returns the device version number. (eg. 1.1 is 101, 1.2 is 102, 2.0 is 200)
uint_ version_number() const
{
if (m_version == 0) {
std::stringstream ss(version());
ushort_ major, minor;
ss.ignore(7); // 'OpenCL '
ss >> major;
ss.ignore(1); // '.'
ss >> minor;
m_version = major * 100 + minor; // cache
}
return m_version;
}

/// Returns the driver version string.
std::string driver_version() const
{
@@ -281,17 +296,11 @@ class device
bool is_subdevice() const
{
#if defined(CL_VERSION_1_2)
try {
if (version_number() >= 102)
return get_info<cl_device_id>(CL_DEVICE_PARENT_DEVICE) != 0;
}
catch(opencl_error&){
// the get_info() call above will throw if the device's opencl version
// is less than 1.2 (in which case it can't be a sub-device).
else
#endif // CL_VERSION_1_2
return false;
}
#else
return false;
#endif
}

/// Returns information about the device.
@@ -327,6 +336,9 @@ class device
std::vector<device>
partition(const cl_device_partition_property *properties) const
{
if (version_number() < 102)
return std::vector<device>();

// get sub-device count
uint_ count = 0;
int_ ret = clCreateSubDevices(m_id, properties, 0, 0, &count);
@@ -405,24 +417,9 @@ class device
return m_id != other.m_id;
}

/// \internal_
bool check_version(int major, int minor) const
{
std::stringstream stream;
stream << version();

int actual_major, actual_minor;
stream.ignore(7); // 'OpenCL '
stream >> actual_major;
stream.ignore(1); // '.'
stream >> actual_minor;

return actual_major > major ||
(actual_major == major && actual_minor >= minor);
}

private:
cl_device_id m_id;
mutable uint_ m_version; // Cached ICD OpenCL version number
};

/// \internal_