|
ViennaCL - The Vienna Computing Library
1.1.2
|
00001 /* ======================================================================= 00002 Copyright (c) 2010, Institute for Microelectronics, TU Vienna. 00003 http://www.iue.tuwien.ac.at 00004 ----------------- 00005 ViennaCL - The Vienna Computing Library 00006 ----------------- 00007 00008 authors: Karl Rupp rupp@iue.tuwien.ac.at 00009 Florian Rudolf flo.rudy+viennacl@gmail.com 00010 Josef Weinbub weinbub@iue.tuwien.ac.at 00011 00012 license: MIT (X11), see file LICENSE in the ViennaCL base directory 00013 ======================================================================= */ 00014 00015 #ifndef _VIENNACL_PLATFORM_HPP_ 00016 #define _VIENNACL_PLATFORM_HPP_ 00017 00022 #ifdef __APPLE__ 00023 #include <OpenCL/cl.h> 00024 #else 00025 #include <CL/cl.h> 00026 #endif 00027 00028 #include <vector> 00029 #include "viennacl/ocl/forwards.h" 00030 #include "viennacl/ocl/device.hpp" 00031 00032 namespace viennacl 00033 { 00034 namespace ocl 00035 { 00036 class platform 00037 { 00038 00039 public: 00040 platform() 00041 { 00042 cl_int err; 00043 cl_uint num_platforms; 00044 cl_platform_id ids[3]; 00045 #if defined(VIENNACL_DEBUG_ALL) 00046 std::cout << "ViennaCL: Getting platform..." << std::endl; 00047 #endif 00048 err = clGetPlatformIDs(1, ids, &num_platforms); 00049 VIENNACL_ERR_CHECK(err); 00050 id_ = ids[0]; 00051 assert(num_platforms > 0 && "ViennaCL: ERROR: No platform found!"); 00052 } 00053 00054 cl_platform_id id() const 00055 { 00056 return id_; 00057 } 00058 00060 std::string info() const 00061 { 00062 char buffer[1024]; 00063 cl_int err; 00064 err = clGetPlatformInfo(id_, CL_PLATFORM_VENDOR, 1024 * sizeof(char), buffer, NULL); 00065 VIENNACL_ERR_CHECK(err); 00066 00067 std::stringstream ss; 00068 ss << buffer << ": "; 00069 00070 err = clGetPlatformInfo(id_, CL_PLATFORM_VERSION, 1024 * sizeof(char), buffer, NULL); 00071 VIENNACL_ERR_CHECK(err); 00072 00073 ss << buffer; 00074 00075 return ss.str(); 00076 } 00077 00079 00080 std::vector<device> devices(cl_device_type dtype = CL_DEVICE_TYPE_DEFAULT) 00081 { 00082 cl_int err; 00083 #if defined(VIENNACL_DEBUG_ALL) || defined(VIENNACL_DEBUG_DEVICE) 00084 std::cout << "ViennaCL: Querying devices available at current platform." << std::endl; 00085 #endif 00086 cl_device_id device_ids[VIENNACL_OCL_MAX_DEVICE_NUM]; 00087 cl_uint num_devices; 00088 err = clGetDeviceIDs(id_, dtype, VIENNACL_OCL_MAX_DEVICE_NUM, device_ids, &num_devices); 00089 if (err == CL_DEVICE_NOT_FOUND && dtype == CL_DEVICE_TYPE_DEFAULT) 00090 { 00091 //workaround for ATI Stream SDK v2.3: No CPUs detected with default device type: 00092 err = clGetDeviceIDs(id_, CL_DEVICE_TYPE_CPU, VIENNACL_OCL_MAX_DEVICE_NUM, device_ids, &num_devices); 00093 } 00094 00095 VIENNACL_ERR_CHECK(err); 00096 #if defined(VIENNACL_DEBUG_ALL) || defined(VIENNACL_DEBUG_DEVICE) 00097 std::cout << "ViennaCL: Found " << num_devices << " devices." << std::endl; 00098 #endif 00099 00100 assert(num_devices > 0 && "Error in viennacl::ocl::platform::devices(): No OpenCL devices available!"); 00101 std::vector<device> devices; 00102 00103 for (cl_uint i=0; i<num_devices; ++i) 00104 devices.push_back(device(device_ids[i])); 00105 00106 return devices; 00107 } 00108 00109 private: 00110 cl_platform_id id_; 00111 }; 00112 00113 } 00114 } 00115 00116 #endif
1.7.6.1