1 //
2 // Copyright 2012 Francisco Jerez
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining a
5 // copy of this software and associated documentation files (the "Software"),
6 // to deal in the Software without restriction, including without limitation
7 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 // and/or sell copies of the Software, and to permit persons to whom the
9 // Software is furnished to do so, subject to the following conditions:
10 //
11 // The above copyright notice and this permission notice shall be included in
12 // all copies or substantial portions of the Software.
13 //
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 // OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 // OTHER DEALINGS IN THE SOFTWARE.
21 //
22
23 #include "api/util.hpp"
24 #include "core/platform.hpp"
25 #include "git_sha1.h"
26
27 using namespace clover;
28
29 namespace {
30 platform _clover_platform;
31 }
32
33 CLOVER_API cl_int
clGetPlatformIDs(cl_uint num_entries,cl_platform_id * rd_platforms,cl_uint * rnum_platforms)34 clGetPlatformIDs(cl_uint num_entries, cl_platform_id *rd_platforms,
35 cl_uint *rnum_platforms) {
36 if ((!num_entries && rd_platforms) ||
37 (!rnum_platforms && !rd_platforms))
38 return CL_INVALID_VALUE;
39
40 if (rnum_platforms)
41 *rnum_platforms = 1;
42 if (rd_platforms)
43 *rd_platforms = desc(_clover_platform);
44
45 return CL_SUCCESS;
46 }
47
48 cl_int
GetPlatformInfo(cl_platform_id d_platform,cl_platform_info param,size_t size,void * r_buf,size_t * r_size)49 clover::GetPlatformInfo(cl_platform_id d_platform, cl_platform_info param,
50 size_t size, void *r_buf, size_t *r_size) try {
51 property_buffer buf { r_buf, size, r_size };
52
53 obj(d_platform);
54
55 switch (param) {
56 case CL_PLATFORM_PROFILE:
57 buf.as_string() = "FULL_PROFILE";
58 break;
59
60 case CL_PLATFORM_VERSION:
61 buf.as_string() = "OpenCL 1.1 Mesa " PACKAGE_VERSION
62 #ifdef MESA_GIT_SHA1
63 " (" MESA_GIT_SHA1 ")"
64 #endif
65 ;
66 break;
67
68 case CL_PLATFORM_NAME:
69 buf.as_string() = "Clover";
70 break;
71
72 case CL_PLATFORM_VENDOR:
73 buf.as_string() = "Mesa";
74 break;
75
76 case CL_PLATFORM_EXTENSIONS:
77 buf.as_string() = "cl_khr_icd";
78 break;
79
80 case CL_PLATFORM_ICD_SUFFIX_KHR:
81 buf.as_string() = "MESA";
82 break;
83
84 default:
85 throw error(CL_INVALID_VALUE);
86 }
87
88 return CL_SUCCESS;
89
90 } catch (error &e) {
91 return e.get();
92 }
93
94 void *
GetExtensionFunctionAddressForPlatform(cl_platform_id d_platform,const char * p_name)95 clover::GetExtensionFunctionAddressForPlatform(cl_platform_id d_platform,
96 const char *p_name) try {
97 obj(d_platform);
98 return GetExtensionFunctionAddress(p_name);
99
100 } catch (error &e) {
101 return NULL;
102 }
103
104 void *
GetExtensionFunctionAddress(const char * p_name)105 clover::GetExtensionFunctionAddress(const char *p_name) {
106 std::string name { p_name };
107
108 if (name == "clIcdGetPlatformIDsKHR")
109 return reinterpret_cast<void *>(IcdGetPlatformIDsKHR);
110 else
111 return NULL;
112 }
113
114 cl_int
IcdGetPlatformIDsKHR(cl_uint num_entries,cl_platform_id * rd_platforms,cl_uint * rnum_platforms)115 clover::IcdGetPlatformIDsKHR(cl_uint num_entries, cl_platform_id *rd_platforms,
116 cl_uint *rnum_platforms) {
117 return clGetPlatformIDs(num_entries, rd_platforms, rnum_platforms);
118 }
119
120 CLOVER_ICD_API cl_int
clGetPlatformInfo(cl_platform_id d_platform,cl_platform_info param,size_t size,void * r_buf,size_t * r_size)121 clGetPlatformInfo(cl_platform_id d_platform, cl_platform_info param,
122 size_t size, void *r_buf, size_t *r_size) {
123 return GetPlatformInfo(d_platform, param, size, r_buf, r_size);
124 }
125
126 CLOVER_ICD_API void *
clGetExtensionFunctionAddress(const char * p_name)127 clGetExtensionFunctionAddress(const char *p_name) {
128 return GetExtensionFunctionAddress(p_name);
129 }
130
131 CLOVER_ICD_API void *
clGetExtensionFunctionAddressForPlatform(cl_platform_id d_platform,const char * p_name)132 clGetExtensionFunctionAddressForPlatform(cl_platform_id d_platform,
133 const char *p_name) {
134 return GetExtensionFunctionAddressForPlatform(d_platform, p_name);
135 }
136
137 CLOVER_ICD_API cl_int
clIcdGetPlatformIDsKHR(cl_uint num_entries,cl_platform_id * rd_platforms,cl_uint * rnum_platforms)138 clIcdGetPlatformIDsKHR(cl_uint num_entries, cl_platform_id *rd_platforms,
139 cl_uint *rnum_platforms) {
140 return IcdGetPlatformIDsKHR(num_entries, rd_platforms, rnum_platforms);
141 }
142