diff --git a/docs/envvars.rst b/docs/envvars.rst index fece46e794c..b65581a16c0 100644 --- a/docs/envvars.rst +++ b/docs/envvars.rst @@ -938,6 +938,7 @@ Rusticl environment variables a comma-separated list of features to enable. Those are disabled by default as they might not be stable enough or break OpenCL conformance. + - ``fp16`` enables OpenCL half support - ``fp64`` enables OpenCL double support .. envvar:: RUSTICL_DEBUG diff --git a/docs/features.txt b/docs/features.txt index 9be1ba1bd58..4ead41fc502 100644 --- a/docs/features.txt +++ b/docs/features.txt @@ -918,7 +918,7 @@ Rusticl extensions that are not part of any OpenCL version: cl_khr_expect_assume in progress cl_khr_extended_async_copies not started cl_khr_extended_bit_ops in progress - cl_khr_fp16 not started + cl_khr_fp16 in progress (llvmpipe, radeonsi, Available with environment variable RUSTICL_FEATURES=fp16) cl_khr_gl_depth_images not started cl_khr_gl_msaa_sharing not started cl_khr_gl_sharing in progress diff --git a/src/gallium/frontends/rusticl/api/device.rs b/src/gallium/frontends/rusticl/api/device.rs index 7b32241e8a0..a7af6236dbe 100644 --- a/src/gallium/frontends/rusticl/api/device.rs +++ b/src/gallium/frontends/rusticl/api/device.rs @@ -89,7 +89,14 @@ impl CLInfo for cl_device_id { CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE => cl_prop::(0), CL_DEVICE_GLOBAL_MEM_SIZE => cl_prop::(dev.global_mem_size()), CL_DEVICE_GLOBAL_VARIABLE_PREFERRED_TOTAL_SIZE => cl_prop::(0), - CL_DEVICE_HALF_FP_CONFIG => cl_prop::(0), + CL_DEVICE_HALF_FP_CONFIG => cl_prop::( + if dev.fp16_supported() { + CL_FP_ROUND_TO_NEAREST | CL_FP_INF_NAN + } else { + 0 + } + .into(), + ), CL_DEVICE_HOST_MEM_CAPABILITIES_INTEL => { cl_prop::(0) } @@ -193,7 +200,9 @@ impl CLInfo for cl_device_id { cl_prop::(if dev.fp64_supported() { 1 } else { 0 }) } CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT => cl_prop::(1), - CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF => cl_prop::(0), + CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF => { + cl_prop::(if dev.fp16_supported() { 1 } else { 0 }) + } CL_DEVICE_NATIVE_VECTOR_WIDTH_INT => cl_prop::(1), CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG => cl_prop::(1), CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT => cl_prop::(1), @@ -232,7 +241,9 @@ impl CLInfo for cl_device_id { cl_prop::(if dev.fp64_supported() { 1 } else { 0 }) } CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT => cl_prop::(1), - CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF => cl_prop::(0), + CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF => { + cl_prop::(if dev.fp16_supported() { 1 } else { 0 }) + } CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT => cl_prop::(1), CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG => cl_prop::(1), CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT => cl_prop::(1), diff --git a/src/gallium/frontends/rusticl/core/device.rs b/src/gallium/frontends/rusticl/core/device.rs index 14b18372e18..4bcebd5cb80 100644 --- a/src/gallium/frontends/rusticl/core/device.rs +++ b/src/gallium/frontends/rusticl/core/device.rs @@ -517,6 +517,10 @@ impl Device { add_spirv("SPV_KHR_integer_dot_product"); add_spirv("SPV_KHR_no_integer_wrap_decoration"); + if self.fp16_supported() { + add_ext(1, 0, 0, "cl_khr_fp16"); + } + if self.fp64_supported() { add_ext(1, 0, 0, "cl_khr_fp64"); add_feat(1, 0, 0, "__opencl_c_fp64"); @@ -616,6 +620,14 @@ impl Device { res as cl_device_type } + pub fn fp16_supported(&self) -> bool { + if !Platform::features().fp16 { + return false; + } + + self.shader_param(pipe_shader_cap::PIPE_SHADER_CAP_FP16) != 0 + } + pub fn fp64_supported(&self) -> bool { if !Platform::features().fp64 { return false; @@ -867,7 +879,7 @@ impl Device { pub fn cl_features(&self) -> clc_optional_features { clc_optional_features { - fp16: false, + fp16: self.fp16_supported(), fp64: self.fp64_supported(), int64: self.int64_supported(), images: self.image_supported(), diff --git a/src/gallium/frontends/rusticl/core/platform.rs b/src/gallium/frontends/rusticl/core/platform.rs index c78d1f00717..719c4b0b6da 100644 --- a/src/gallium/frontends/rusticl/core/platform.rs +++ b/src/gallium/frontends/rusticl/core/platform.rs @@ -21,6 +21,7 @@ pub struct PlatformDebug { } pub struct PlatformFeatures { + pub fp16: bool, pub fp64: bool, } @@ -55,7 +56,10 @@ static mut PLATFORM: Platform = Platform { devs: Vec::new(), }; static mut PLATFORM_DBG: PlatformDebug = PlatformDebug { program: false }; -static mut PLATFORM_FEATURES: PlatformFeatures = PlatformFeatures { fp64: false }; +static mut PLATFORM_FEATURES: PlatformFeatures = PlatformFeatures { + fp16: false, + fp64: false, +}; fn load_env() { let debug = unsafe { &mut PLATFORM_DBG }; @@ -72,6 +76,7 @@ fn load_env() { if let Ok(feature_flags) = env::var("RUSTICL_FEATURES") { for flag in feature_flags.split(',') { match flag { + "fp16" => features.fp16 = true, "fp64" => features.fp64 = true, _ => eprintln!("Unknown RUSTICL_FEATURES flag found: {}", flag), } diff --git a/src/gallium/frontends/rusticl/mesa/compiler/clc/spirv.rs b/src/gallium/frontends/rusticl/mesa/compiler/clc/spirv.rs index 641ecc898ae..802d712db96 100644 --- a/src/gallium/frontends/rusticl/mesa/compiler/clc/spirv.rs +++ b/src/gallium/frontends/rusticl/mesa/compiler/clc/spirv.rs @@ -319,6 +319,7 @@ impl SPIRVBin { caps: spirv_supported_capabilities { address: true, + float16: true, float64: true, generic_pointers: true, int8: true,