diff --git a/example/amd_cpp_kernel.cpp b/example/amd_cpp_kernel.cpp index 20bba201..87e8de6f 100644 --- a/example/amd_cpp_kernel.cpp +++ b/example/amd_cpp_kernel.cpp @@ -30,10 +30,9 @@ int main() compute::device device = compute::system::default_device(); compute::context context(device); compute::command_queue queue(context, device); - compute::platform platform(device.get_info()); // check the platform vendor string - if(platform.vendor() != "Advanced Micro Devices, Inc."){ + if(device.platform().vendor() != "Advanced Micro Devices, Inc."){ std::cerr << "error: static C++ kernel language is only " << "supported on AMD devices." << std::endl; diff --git a/include/boost/compute/detail/vendor.hpp b/include/boost/compute/detail/vendor.hpp index 8e4593fa..f01116ba 100644 --- a/include/boost/compute/detail/vendor.hpp +++ b/include/boost/compute/detail/vendor.hpp @@ -12,6 +12,7 @@ #define BOOST_COMPUTE_DETAIL_VENDOR_HPP #include +#include namespace boost { namespace compute { @@ -26,11 +27,7 @@ inline bool is_nvidia_device(const device &device) // returns true if the device is an amd cpu or gpu inline bool is_amd_device(const device &device) { - platform device_platform( - device.get_info(CL_DEVICE_PLATFORM) - ); - - return device_platform.vendor() == "Advanced Micro Devices, Inc."; + return device.platform().vendor() == "Advanced Micro Devices, Inc."; } } // end detail namespace diff --git a/include/boost/compute/device.hpp b/include/boost/compute/device.hpp index 94ba0549..8d45c219 100644 --- a/include/boost/compute/device.hpp +++ b/include/boost/compute/device.hpp @@ -26,6 +26,8 @@ namespace boost { namespace compute { +class platform; + /// \class device /// \brief A compute device. /// @@ -155,6 +157,13 @@ public: return get_info(CL_DEVICE_TYPE); } + #ifdef BOOST_COMPUTE_DOXYGEN_INVOKED + /// Returns the platform for the device. + platform platform() const; + #else + boost::compute::platform platform() const; + #endif + /// Returns the name of the device. std::string name() const { diff --git a/include/boost/compute/platform.hpp b/include/boost/compute/platform.hpp index d5412bda..7dc68d8d 100644 --- a/include/boost/compute/platform.hpp +++ b/include/boost/compute/platform.hpp @@ -222,6 +222,11 @@ BOOST_COMPUTE_DETAIL_DEFINE_GET_INFO_SPECIALIZATIONS(platform, ((std::string, CL_PLATFORM_EXTENSIONS)) ) +inline boost::compute::platform device::platform() const +{ + return boost::compute::platform(get_info()); +} + } // end compute namespace } // end boost namespace diff --git a/include/boost/compute/program.hpp b/include/boost/compute/program.hpp index 81949ae5..6e876602 100644 --- a/include/boost/compute/program.hpp +++ b/include/boost/compute/program.hpp @@ -508,7 +508,7 @@ public: std::string hash; { device d(context.get_device()); - platform p(d.get_info(CL_DEVICE_PLATFORM)); + platform p = d.platform(); std::ostringstream src; src << "// " << p.name() << " v" << p.version() << "\n" diff --git a/include/boost/compute/system.hpp b/include/boost/compute/system.hpp index d9dd3b6a..d190167f 100644 --- a/include/boost/compute/system.hpp +++ b/include/boost/compute/system.hpp @@ -219,7 +219,7 @@ private: if (device.type() != device::cpu) continue; - if (platform && !matches(device_platform(device).name(), platform)) + if (platform && !matches(device.platform().name(), platform)) continue; if (vendor && !matches(device.vendor(), vendor)) @@ -247,12 +247,6 @@ private: return devices_[0]; } - /// \internal_ - static platform device_platform(const device &device) - { - return platform(device.get_info(CL_DEVICE_PLATFORM)); - } - /// \internal_ static bool matches(const std::string &str, const std::string &pattern) { diff --git a/test/quirks.hpp b/test/quirks.hpp index c162d22e..7a7f2e31 100644 --- a/test/quirks.hpp +++ b/test/quirks.hpp @@ -22,11 +22,7 @@ // returns true if the device is a POCL device inline bool is_pocl_device(const boost::compute::device &device) { - boost::compute::platform platform( - device.get_info(CL_DEVICE_PLATFORM) - ); - - return platform.name() == "Portable Computing Language"; + return device.platform().name() == "Portable Computing Language"; } // AMD platforms have a bug when using struct assignment. this affects diff --git a/test/test_device.cpp b/test/test_device.cpp index 1ed87216..1946418a 100644 --- a/test/test_device.cpp +++ b/test/test_device.cpp @@ -35,6 +35,12 @@ boost::compute::device gpu = boost::compute::system::default_device(); BOOST_CHECK(gpu.id()); } +BOOST_AUTO_TEST_CASE(device_platform) +{ + boost::compute::platform p = boost::compute::system::platforms().at(0); + BOOST_CHECK(p == p.devices().at(0).platform()); +} + BOOST_AUTO_TEST_CASE(get_device_name) { boost::compute::device gpu = boost::compute::system::default_device();