From 82b477751ed3e3249c46a8c96ace537669e31066 Mon Sep 17 00:00:00 2001 From: Karol Herbst Date: Tue, 3 May 2022 21:52:42 +0200 Subject: [PATCH] rusticl/device: allow overwriting the device_type via env Signed-off-by: Karol Herbst Acked-by: Alyssa Rosenzweig Part-of: --- src/gallium/frontends/rusticl/core/device.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/gallium/frontends/rusticl/core/device.rs b/src/gallium/frontends/rusticl/core/device.rs index 1ab3bd22129..f4d4628792c 100644 --- a/src/gallium/frontends/rusticl/core/device.rs +++ b/src/gallium/frontends/rusticl/core/device.rs @@ -289,6 +289,21 @@ impl Device { !self.long_supported() } + fn parse_env_device_type() -> Option { + let mut val = env::var("RUSTICL_DEVICE_TYPE").ok()?; + val.make_ascii_lowercase(); + Some( + match &*val { + "accelerator" => CL_DEVICE_TYPE_ACCELERATOR, + "cpu" => CL_DEVICE_TYPE_CPU, + "custom" => CL_DEVICE_TYPE_CUSTOM, + "gpu" => CL_DEVICE_TYPE_GPU, + _ => return None, + } + .into(), + ) + } + fn parse_env_version() -> Option { let val = env::var("RUSTICL_CL_VERSION").ok()?; let (major, minor) = val.split_once('.')?; @@ -458,6 +473,10 @@ impl Device { } pub fn device_type(&self, internal: bool) -> cl_device_type { + if let Some(env) = Self::parse_env_device_type() { + return env; + } + if self.custom { return CL_DEVICE_TYPE_CUSTOM as cl_device_type; }