From a40d4c0346cca31ac64b981ce82608d92a7cd292 Mon Sep 17 00:00:00 2001 From: Karol Herbst Date: Fri, 18 Mar 2022 01:06:20 +0100 Subject: [PATCH] rusticl/kernel: implement clCloneKernel Signed-off-by: Karol Herbst Acked-by: Alyssa Rosenzweig Part-of: --- src/gallium/frontends/rusticl/api/icd.rs | 6 +++++- src/gallium/frontends/rusticl/api/kernel.rs | 5 +++++ src/gallium/frontends/rusticl/core/kernel.rs | 23 +++++++++++++++++++--- .../frontends/rusticl/mesa/compiler/clc/spirv.rs | 2 +- src/gallium/frontends/rusticl/mesa/compiler/nir.rs | 8 ++++++++ 5 files changed, 39 insertions(+), 5 deletions(-) diff --git a/src/gallium/frontends/rusticl/api/icd.rs b/src/gallium/frontends/rusticl/api/icd.rs index f1395ba..801ab02 100644 --- a/src/gallium/frontends/rusticl/api/icd.rs +++ b/src/gallium/frontends/rusticl/api/icd.rs @@ -159,7 +159,7 @@ pub static DISPATCH: cl_icd_dispatch = cl_icd_dispatch { clSetKernelArgSVMPointer: None, clSetKernelExecInfo: None, clGetKernelSubGroupInfoKHR: None, - clCloneKernel: None, + clCloneKernel: Some(cl_clone_kernel), clCreateProgramWithIL: None, clEnqueueSVMMigrateMem: None, clGetDeviceAndHostTimer: None, @@ -1503,6 +1503,10 @@ extern "C" fn cl_create_command_queue_with_properties( match_obj!(create_command_queue(context, device, 0), errcode_ret) } +extern "C" fn cl_clone_kernel(source_kernel: cl_kernel, errcode_ret: *mut cl_int) -> cl_kernel { + match_obj!(clone_kernel(source_kernel), errcode_ret) +} + extern "C" fn cl_set_context_destructor_callback( context: cl_context, pfn_notify: ::std::option::Option, diff --git a/src/gallium/frontends/rusticl/api/kernel.rs b/src/gallium/frontends/rusticl/api/kernel.rs index 02a90c8..0fed38d 100644 --- a/src/gallium/frontends/rusticl/api/kernel.rs +++ b/src/gallium/frontends/rusticl/api/kernel.rs @@ -420,3 +420,8 @@ pub fn enqueue_task( event, ) } + +pub fn clone_kernel(source_kernel: cl_kernel) -> CLResult { + let k = source_kernel.get_ref()?; + Ok(cl_kernel::from_arc(Arc::new(k.clone()))) +} diff --git a/src/gallium/frontends/rusticl/core/kernel.rs b/src/gallium/frontends/rusticl/core/kernel.rs index 3eb6314..05037c6 100644 --- a/src/gallium/frontends/rusticl/core/kernel.rs +++ b/src/gallium/frontends/rusticl/core/kernel.rs @@ -24,6 +24,7 @@ use std::ptr; use std::sync::Arc; // ugh, we are not allowed to take refs, so... +#[derive(Clone)] pub enum KernelArgValue { None, Constant(Vec), @@ -32,7 +33,7 @@ pub enum KernelArgValue { LocalMem(usize), } -#[derive(PartialEq, Eq)] +#[derive(PartialEq, Eq, Clone)] pub enum KernelArgType { Constant, // for anything passed by value Sampler, @@ -41,12 +42,13 @@ pub enum KernelArgType { MemLocal, } -#[derive(Hash, PartialEq, Eq)] +#[derive(Hash, PartialEq, Eq, Clone)] pub enum InternalKernelArgType { ConstantBuffer, GlobalWorkOffsets, } +#[derive(Clone)] pub struct KernelArg { spirv: spirv::SPIRVKernelArg, pub kind: KernelArgType, @@ -55,7 +57,7 @@ pub struct KernelArg { pub dead: bool, } -#[derive(Hash, PartialEq, Eq)] +#[derive(Hash, PartialEq, Eq, Clone)] pub struct InternalKernelArg { pub kind: InternalKernelArgType, pub size: usize, @@ -541,3 +543,18 @@ impl Kernel { self.nirs.get(dev).unwrap().shared_size() as cl_ulong } } + +impl Clone for Kernel { + fn clone(&self) -> Self { + Self { + base: CLObjectBase::new(), + prog: self.prog.clone(), + name: self.name.clone(), + args: self.args.clone(), + values: self.values.clone(), + work_group_size: self.work_group_size, + internal_args: self.internal_args.clone(), + nirs: self.nirs.clone(), + } + } +} diff --git a/src/gallium/frontends/rusticl/mesa/compiler/clc/spirv.rs b/src/gallium/frontends/rusticl/mesa/compiler/clc/spirv.rs index 7bf8258..651dbe1 100644 --- a/src/gallium/frontends/rusticl/mesa/compiler/clc/spirv.rs +++ b/src/gallium/frontends/rusticl/mesa/compiler/clc/spirv.rs @@ -20,7 +20,7 @@ pub struct SPIRVBin { info: Option, } -#[derive(PartialEq, Eq, Hash)] +#[derive(PartialEq, Eq, Hash, Clone)] pub struct SPIRVKernelArg { pub name: String, pub type_name: String, diff --git a/src/gallium/frontends/rusticl/mesa/compiler/nir.rs b/src/gallium/frontends/rusticl/mesa/compiler/nir.rs index ca1d51a..ba1e8ca 100644 --- a/src/gallium/frontends/rusticl/mesa/compiler/nir.rs +++ b/src/gallium/frontends/rusticl/mesa/compiler/nir.rs @@ -218,6 +218,14 @@ impl NirShader { } } +impl Clone for NirShader { + fn clone(&self) -> Self { + Self { + nir: NonNull::new(self.dup_for_driver()).unwrap(), + } + } +} + impl Drop for NirShader { fn drop(&mut self) { unsafe { ralloc_free(self.nir.as_ptr().cast()) }; -- 2.7.4