mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-20 07:20:10 +01:00
clover: implement CLOVER_DEVICE_TYPE like RUSTICL_DEVICE_TYPE
Allows to make Clover devices appearing as cpu, gpu or accelerator by setting the CLOVER_DEVICE_TYPE environment variable like the RUSTICL_DEVICE_TYPE environment variable does. For example it can make the CPU llvmpipe device appear as GPU or GPU devices appear as CPU. This is useful for testing OpenCL with applications that may use different code path given the OpenCL device is a CPU or a GPU. The initial motivation for RUSTICL_DEVICE_TYPE implementation was to test rusticl with llvmipe on applications ignoring CPU devices. This brings Clover on par with rusticl on that topic. CL_DEVICE_TYPE_CUSTOM isn't implemented or applications may crash when iterating devices because CL_DEVICE_TYPE_CUSTOM is OpenCL 1.2 and Clover is OpenCL 1.1. Signed-off-by: Thomas Debesse <dev@illwieckz.net> Reviewed-by: Mihai Preda <mhpreda@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18931>
This commit is contained in:
parent
6113ee650a
commit
981bc603b4
1 changed files with 26 additions and 0 deletions
|
|
@ -134,6 +134,27 @@ namespace {
|
|||
|
||||
return version;
|
||||
}
|
||||
|
||||
static cl_device_type
|
||||
parse_env_device_type() {
|
||||
const char* val = getenv("CLOVER_DEVICE_TYPE");
|
||||
if (!val) {
|
||||
return 0;
|
||||
}
|
||||
if (strcmp(val, "cpu") == 0) {
|
||||
return CL_DEVICE_TYPE_CPU;
|
||||
}
|
||||
if (strcmp(val, "gpu") == 0) {
|
||||
return CL_DEVICE_TYPE_GPU;
|
||||
}
|
||||
if (strcmp(val, "accelerator") == 0) {
|
||||
return CL_DEVICE_TYPE_ACCELERATOR;
|
||||
}
|
||||
/* CL_DEVICE_TYPE_CUSTOM isn't implemented
|
||||
because CL_DEVICE_TYPE_CUSTOM is OpenCL 1.2
|
||||
and Clover is OpenCL 1.1. */
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
device::device(clover::platform &platform, pipe_loader_device *ldev) :
|
||||
|
|
@ -189,6 +210,11 @@ device::operator==(const device &dev) const {
|
|||
|
||||
cl_device_type
|
||||
device::type() const {
|
||||
cl_device_type type = parse_env_device_type();
|
||||
if (type != 0) {
|
||||
return type;
|
||||
}
|
||||
|
||||
switch (ldev->type) {
|
||||
case PIPE_LOADER_DEVICE_SOFTWARE:
|
||||
return CL_DEVICE_TYPE_CPU;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue