From afe95b613c076835ff1dfc99ec427e2db3f7e251 Mon Sep 17 00:00:00 2001 From: Karol Herbst Date: Sat, 8 Jul 2023 17:38:02 +0200 Subject: [PATCH] rusticl: Replace &Arc with &Device Part-of: --- src/gallium/frontends/rusticl/api/context.rs | 4 +-- src/gallium/frontends/rusticl/api/device.rs | 6 ++--- src/gallium/frontends/rusticl/core/kernel.rs | 6 ++--- src/gallium/frontends/rusticl/core/memory.rs | 2 +- src/gallium/frontends/rusticl/core/program.rs | 27 ++++++++----------- 5 files changed, 20 insertions(+), 25 deletions(-) diff --git a/src/gallium/frontends/rusticl/api/context.rs b/src/gallium/frontends/rusticl/api/context.rs index a16c2059bb1..f58668b0c9d 100644 --- a/src/gallium/frontends/rusticl/api/context.rs +++ b/src/gallium/frontends/rusticl/api/context.rs @@ -97,8 +97,8 @@ fn create_context_from_type( check_cl_device_type(device_type)?; let devs: Vec<_> = get_devs_for_type(device_type) - .iter() - .map(|d| cl_device_id::from_ptr(Arc::as_ptr(d))) + .into_iter() + .map(|d| cl_device_id::from_ptr(d)) .collect(); // CL_DEVICE_NOT_FOUND if no devices that match device_type and property values specified in properties were found. diff --git a/src/gallium/frontends/rusticl/api/device.rs b/src/gallium/frontends/rusticl/api/device.rs index 681db4418b5..bea08a45420 100644 --- a/src/gallium/frontends/rusticl/api/device.rs +++ b/src/gallium/frontends/rusticl/api/device.rs @@ -320,10 +320,11 @@ fn devs() -> &'static Vec> { &Platform::get().devs } -pub fn get_devs_for_type(device_type: cl_device_type) -> Vec<&'static Arc> { +pub fn get_devs_for_type(device_type: cl_device_type) -> Vec<&'static Device> { devs() .iter() .filter(|d| device_type & d.device_type(true) != 0) + .map(Arc::as_ref) .collect() } @@ -367,8 +368,7 @@ fn get_device_ids( #[allow(clippy::needless_range_loop)] for i in 0..n { unsafe { - // Note we use as_ptr here which doesn't increase the reference count. - *devices.add(i) = cl_device_id::from_ptr(Arc::as_ptr(devs[i])); + *devices.add(i) = cl_device_id::from_ptr(devs[i]); } } } diff --git a/src/gallium/frontends/rusticl/core/kernel.rs b/src/gallium/frontends/rusticl/core/kernel.rs index 1298e1fc108..215161fe079 100644 --- a/src/gallium/frontends/rusticl/core/kernel.rs +++ b/src/gallium/frontends/rusticl/core/kernel.rs @@ -734,7 +734,7 @@ pub(super) fn convert_spirv_to_nir( build: &ProgramBuild, name: &str, args: &[spirv::SPIRVKernelArg], - dev: &Arc, + dev: &Device, ) -> (NirShader, Vec, Vec) { let cache = dev.screen().shader_cache(); let key = build.hash_key(dev, name); @@ -1192,7 +1192,7 @@ impl Kernel { &self.build.args[idx as usize].spirv.type_name } - pub fn priv_mem_size(&self, dev: &Arc) -> cl_ulong { + pub fn priv_mem_size(&self, dev: &Device) -> cl_ulong { self.dev_state.get(dev).info.private_memory.into() } @@ -1204,7 +1204,7 @@ impl Kernel { self.dev_state.get(dev).info.preferred_simd_size as usize } - pub fn local_mem_size(&self, dev: &Arc) -> cl_ulong { + pub fn local_mem_size(&self, dev: &Device) -> cl_ulong { // TODO include args self.dev_state.get(dev).nir.shared_size() as cl_ulong } diff --git a/src/gallium/frontends/rusticl/core/memory.rs b/src/gallium/frontends/rusticl/core/memory.rs index bb0f4535f28..343d450aa70 100644 --- a/src/gallium/frontends/rusticl/core/memory.rs +++ b/src/gallium/frontends/rusticl/core/memory.rs @@ -577,7 +577,7 @@ impl Mem { self.get_parent().res.as_ref().ok_or(CL_OUT_OF_HOST_MEMORY) } - pub fn get_res_of_dev(&self, dev: &Arc) -> CLResult<&Arc> { + pub fn get_res_of_dev(&self, dev: &Device) -> CLResult<&Arc> { Ok(self.get_res()?.get(dev).unwrap()) } diff --git a/src/gallium/frontends/rusticl/core/program.rs b/src/gallium/frontends/rusticl/core/program.rs index 0563091cbc6..3bfe33a3b80 100644 --- a/src/gallium/frontends/rusticl/core/program.rs +++ b/src/gallium/frontends/rusticl/core/program.rs @@ -83,7 +83,7 @@ pub(super) struct ProgramBuild { } impl ProgramBuild { - fn attribute_str(&self, kernel: &str, d: &Arc) -> String { + fn attribute_str(&self, kernel: &str, d: &Device) -> String { let info = self.dev_build(d); let attributes_strings = [ @@ -100,7 +100,7 @@ impl ProgramBuild { attributes_strings.join(",") } - fn args(&self, dev: &Arc, kernel: &str) -> Vec { + fn args(&self, dev: &Device, kernel: &str) -> Vec { self.dev_build(dev).spirv.as_ref().unwrap().args(kernel) } @@ -171,7 +171,7 @@ impl ProgramBuild { .collect() } - pub fn hash_key(&self, dev: &Arc, name: &str) -> Option { + pub fn hash_key(&self, dev: &Device, name: &str) -> Option { if let Some(cache) = dev.screen().shader_cache() { let info = self.dev_build(dev); assert_eq!(info.status, CL_BUILD_SUCCESS as cl_build_status); @@ -194,7 +194,7 @@ impl ProgramBuild { } } - pub fn to_nir(&self, kernel: &str, d: &Arc) -> NirShader { + pub fn to_nir(&self, kernel: &str, d: &Device) -> NirShader { let mut spec_constants: Vec<_> = self .spec_constants .iter() @@ -417,19 +417,19 @@ impl Program { info.kernel_builds.get(name).unwrap().clone() } - pub fn status(&self, dev: &Arc) -> cl_build_status { + pub fn status(&self, dev: &Device) -> cl_build_status { self.build_info().dev_build(dev).status } - pub fn log(&self, dev: &Arc) -> String { + pub fn log(&self, dev: &Device) -> String { self.build_info().dev_build(dev).log.clone() } - pub fn bin_type(&self, dev: &Arc) -> cl_program_binary_type { + pub fn bin_type(&self, dev: &Device) -> cl_program_binary_type { self.build_info().dev_build(dev).bin_type } - pub fn options(&self, dev: &Arc) -> String { + pub fn options(&self, dev: &Device) -> String { self.build_info().dev_build(dev).options.clone() } @@ -514,7 +514,7 @@ impl Program { .any(|b| Arc::strong_count(b) > 1) } - pub fn build(&self, dev: &Arc, options: String) -> bool { + pub fn build(&self, dev: &Device, options: String) -> bool { let lib = options.contains("-create-library"); let mut info = self.build_info(); if !self.do_compile(dev, options, &Vec::new(), &mut info) { @@ -557,7 +557,7 @@ impl Program { fn do_compile( &self, - dev: &Arc, + dev: &Device, options: String, headers: &[spirv::CLCHeader], info: &mut MutexGuard, @@ -619,12 +619,7 @@ impl Program { } } - pub fn compile( - &self, - dev: &Arc, - options: String, - headers: &[spirv::CLCHeader], - ) -> bool { + pub fn compile(&self, dev: &Device, options: String, headers: &[spirv::CLCHeader]) -> bool { self.do_compile(dev, options, headers, &mut self.build_info()) }