1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
use crate::objects::enums::{ParamValue, Size};
use crate::objects::functions::{bytes_into_string, status_update};
use crate::objects::structs::PlatformInfo;
use crate::objects::types::{APIResult, PlatformList, PlatformPtr};
use crate::{gen_object_list, gen_param_value, get_count, size_getter};
use libc::c_void;
use opencl_heads::ffi::*;
use std::ptr;
pub fn get_platform_ids() -> APIResult<PlatformList> {
let platform_count = get_count!(clGetPlatformIDs);
if platform_count == 0 {
Ok(Vec::default())
} else {
gen_object_list!(clGetPlatformIDs, PlatformList, platform_count)
}
}
pub fn get_platform_info(
platform: &PlatformPtr,
param_name: cl_platform_info,
) -> APIResult<ParamValue> {
type P = PlatformInfo;
let platform = platform.unwrap();
size_getter!(get_platform_info_size, clGetPlatformInfo);
let fn_name = "clGetPlatformInfo";
match param_name {
P::PROFILE | P::VERSION | P::VENDOR | P::NAME | P::EXTENSIONS => {
let size = get_platform_info_size(platform, param_name)?;
let param_value = gen_param_value!(clGetPlatformInfo, u8, platform, param_name, size);
Ok(ParamValue::String(bytes_into_string(param_value)?))
}
P::HOST_TIMER_RESOLUTION => {
let param_value = gen_param_value!(clGetPlatformInfo, u64, platform, param_name);
Ok(ParamValue::ULong(param_value))
}
P::NUMERIC_VERSION => {
let param_value = gen_param_value!(clGetPlatformInfo, u32, platform, param_name);
Ok(ParamValue::UInt(param_value))
}
P::EXTENSIONS_WITH_VERSION => {
let size = get_platform_info_size(platform, param_name)?;
let param_value = gen_param_value!(
clGetPlatformInfo,
cl_name_version,
platform,
param_name,
size
);
Ok(ParamValue::NameVersion(param_value))
}
_ => status_update(40404, fn_name, ParamValue::default()),
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_get_platform_ids() {
let id = get_platform_ids().unwrap();
assert_ne!(id, vec!(ptr::null_mut()));
assert_ne!(id, vec!());
}
#[test]
fn test_get_platform_info() {
let all_platforms = get_platform_ids().unwrap();
let id = PlatformPtr::from_ptr(all_platforms[0], "main_fn").unwrap();
let name = get_platform_info(&id, PlatformInfo::NAME).unwrap();
println!("CL_PLATFORM_NAME: {:?}", name);
assert_ne!(name.unwrap_string().unwrap(), "");
let version = get_platform_info(&id, PlatformInfo::VERSION).unwrap();
println!("CL_PLATFORM_VERSION: {:?}", version);
assert_ne!(version.unwrap_string().unwrap(), "");
let vendor = get_platform_info(&id, PlatformInfo::VENDOR).unwrap();
println!("CL_PLATFORM_VENDOR: {:?}", vendor);
assert_ne!(vendor.unwrap_string().unwrap(), "");
let profile = get_platform_info(&id, PlatformInfo::PROFILE).unwrap();
println!("CL_PLATFORM_PROFILE: {:?}", profile);
assert_ne!(profile.unwrap_string().unwrap(), "");
let extensions = get_platform_info(&id, PlatformInfo::EXTENSIONS).unwrap();
println!("CL_PLATFORM_EXTENSIONS: {:?}", extensions);
assert_ne!(extensions.unwrap_string().unwrap(), "");
}
#[test]
#[ignore]
fn test_get_platform_info_fail() {
let all_platforms = get_platform_ids().unwrap();
let id = PlatformPtr::from_ptr(all_platforms[0], "main_fn").unwrap();
let wrong_id = 666;
let extensions = get_platform_info(&id, wrong_id)
.expect_err("Wrong ID entered, check your structs dude!");
println!("CL_PLATFORM_INVALID: {:?}", extensions);
}
#[test]
#[cfg(feature = "cl_2_0")]
fn test_get_platform_info_v2() {
let all_platforms = get_platform_ids().unwrap();
let id = PlatformPtr::from_ptr(all_platforms[0], "main_fn").unwrap();
let extversion = get_platform_info(&id, PlatformInfo::HOST_TIMER_RESOLUTION).unwrap();
println!("CL_PLATFORM_HOST_TIMER_RESOLUTION: {:?}", extversion);
assert_ne!(extversion.unwrap_ulong().unwrap(), 0);
}
#[test]
#[cfg(feature = "cl_3_0")]
fn test_get_platform_info_v3() {
let all_platforms = get_platform_ids().unwrap();
println!("Number of platforms: {}", all_platforms.len());
let id = all_platforms[0];
let numver = get_platform_info(id, PlatformInfo::NUMERIC_VERSION).unwrap();
println!("CL_PLATFORM_NUMERIC_VERSION: {:?}", numver);
assert_eq!(numver.unwrap_uint().unwrap(), 0);
let extversion = get_platform_info(id, PlatformInfo::EXTENSIONS_WITH_VERSION).unwrap();
println!("CL_PLATFORM_EXTENSIONS_WITH_VERSION: {:?}", extversion);
assert_ne!(extversion.unwrap_name_version().unwrap().len(), 0);
}
}