rusticl: experimental support for cl_khr_fp16
Hidden behind `RUSTICL_ENABLE=fp16` for now as the OpenCL CTS doesn't have enough fp16 tests at the moment. There has been a lot of work on it though, so hopefully we can enable and verify it soon. Additionally libclc also misses a bunch of fp16 functionality, so most of the tests would also just crash. However this flag is useful for development as it already wires up most of the code needed. Signed-off-by: Karol Herbst <git@karolherbst.de> Reviewed-by: Nora Allen <blackcatgames@protonmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23788>
This commit is contained in:
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -89,7 +89,14 @@ impl CLInfo<cl_device_info> for cl_device_id {
|
||||
CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE => cl_prop::<cl_uint>(0),
|
||||
CL_DEVICE_GLOBAL_MEM_SIZE => cl_prop::<cl_ulong>(dev.global_mem_size()),
|
||||
CL_DEVICE_GLOBAL_VARIABLE_PREFERRED_TOTAL_SIZE => cl_prop::<usize>(0),
|
||||
CL_DEVICE_HALF_FP_CONFIG => cl_prop::<cl_device_fp_config>(0),
|
||||
CL_DEVICE_HALF_FP_CONFIG => cl_prop::<cl_device_fp_config>(
|
||||
if dev.fp16_supported() {
|
||||
CL_FP_ROUND_TO_NEAREST | CL_FP_INF_NAN
|
||||
} else {
|
||||
0
|
||||
}
|
||||
.into(),
|
||||
),
|
||||
CL_DEVICE_HOST_MEM_CAPABILITIES_INTEL => {
|
||||
cl_prop::<cl_device_unified_shared_memory_capabilities_intel>(0)
|
||||
}
|
||||
@@ -193,7 +200,9 @@ impl CLInfo<cl_device_info> for cl_device_id {
|
||||
cl_prop::<cl_uint>(if dev.fp64_supported() { 1 } else { 0 })
|
||||
}
|
||||
CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT => cl_prop::<cl_uint>(1),
|
||||
CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF => cl_prop::<cl_uint>(0),
|
||||
CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF => {
|
||||
cl_prop::<cl_uint>(if dev.fp16_supported() { 1 } else { 0 })
|
||||
}
|
||||
CL_DEVICE_NATIVE_VECTOR_WIDTH_INT => cl_prop::<cl_uint>(1),
|
||||
CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG => cl_prop::<cl_uint>(1),
|
||||
CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT => cl_prop::<cl_uint>(1),
|
||||
@@ -232,7 +241,9 @@ impl CLInfo<cl_device_info> for cl_device_id {
|
||||
cl_prop::<cl_uint>(if dev.fp64_supported() { 1 } else { 0 })
|
||||
}
|
||||
CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT => cl_prop::<cl_uint>(1),
|
||||
CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF => cl_prop::<cl_uint>(0),
|
||||
CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF => {
|
||||
cl_prop::<cl_uint>(if dev.fp16_supported() { 1 } else { 0 })
|
||||
}
|
||||
CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT => cl_prop::<cl_uint>(1),
|
||||
CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG => cl_prop::<cl_uint>(1),
|
||||
CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT => cl_prop::<cl_uint>(1),
|
||||
|
@@ -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(),
|
||||
|
@@ -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),
|
||||
}
|
||||
|
@@ -319,6 +319,7 @@ impl SPIRVBin {
|
||||
|
||||
caps: spirv_supported_capabilities {
|
||||
address: true,
|
||||
float16: true,
|
||||
float64: true,
|
||||
generic_pointers: true,
|
||||
int8: true,
|
||||
|
Reference in New Issue
Block a user