From 5cb328d002ecd99011c3dc1eb5304d10f84b3855 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Se=C3=A1n=20de=20B=C3=BArca?= Date: Sat, 2 Aug 2025 10:36:37 -0700 Subject: [PATCH] rusticl: move debug logging to the end of the build step Reviewed-by: Karol Herbst Part-of: --- src/gallium/frontends/rusticl/api/program.rs | 20 +---------- src/gallium/frontends/rusticl/core/program.rs | 33 ++++++++++++++++--- 2 files changed, 30 insertions(+), 23 deletions(-) diff --git a/src/gallium/frontends/rusticl/api/program.rs b/src/gallium/frontends/rusticl/api/program.rs index 485c8bc46e8..f569b3190eb 100644 --- a/src/gallium/frontends/rusticl/api/program.rs +++ b/src/gallium/frontends/rusticl/api/program.rs @@ -3,7 +3,6 @@ use crate::api::types::*; use crate::api::util::*; use crate::core::context::*; use crate::core::device::*; -use crate::core::platform::*; use crate::core::program::*; use mesa_rust::compiler::clc::*; @@ -302,17 +301,6 @@ fn release_program(program: cl_program) -> CLResult<()> { Program::release(program) } -fn debug_logging(p: &Program, devs: &[&Device]) { - if Platform::dbg().program { - for dev in devs { - let msg = p.log(dev); - if !msg.is_empty() { - eprintln!("{}", msg); - } - } - } -} - #[cl_entrypoint(clBuildProgram)] fn build_program( program: cl_program, @@ -348,7 +336,6 @@ fn build_program( //• CL_INVALID_OPERATION if the build of a program executable for any of the devices listed in device_list by a previous call to clBuildProgram for program has not completed. //• CL_INVALID_OPERATION if program was not created with clCreateProgramWithSource, clCreateProgramWithIL or clCreateProgramWithBinary. - debug_logging(p, &devs); if res { Ok(()) } else { @@ -368,7 +355,6 @@ fn compile_program( pfn_notify: Option, user_data: *mut ::std::os::raw::c_void, ) -> CLResult<()> { - let mut res = true; let p = Program::ref_from_raw(program)?; let devs = validate_devices(device_list, num_devices, &p.devs)?; @@ -418,9 +404,7 @@ fn compile_program( // CL_COMPILE_PROGRAM_FAILURE if there is a failure to compile the program source. This error // will be returned if clCompileProgram does not return until the compile has completed. let options = c_string_to_string(options); - for dev in &devs { - res &= p.compile(dev, &options, &headers); - } + let res = p.compile(&devs, &options, &headers); if let Some(cb) = cb_opt { cb.call(p); @@ -429,7 +413,6 @@ fn compile_program( // • CL_INVALID_COMPILER_OPTIONS if the compiler options specified by options are invalid. // • CL_INVALID_OPERATION if the compilation or build of a program executable for any of the devices listed in device_list by a previous call to clCompileProgram or clBuildProgram for program has not completed. - debug_logging(p, &devs); if res { Ok(()) } else { @@ -495,7 +478,6 @@ pub fn link_program( cb.call(&res); } - debug_logging(&res, &devs); Ok((res.into_cl(), code)) //• CL_INVALID_LINKER_OPTIONS if the linker options specified by options are invalid. diff --git a/src/gallium/frontends/rusticl/core/program.rs b/src/gallium/frontends/rusticl/core/program.rs index 78b9063aa8e..11018531422 100644 --- a/src/gallium/frontends/rusticl/core/program.rs +++ b/src/gallium/frontends/rusticl/core/program.rs @@ -597,6 +597,8 @@ impl Program { info.rebuild_kernels(devs, self.is_src()); + debug_logging(self, devs); + res } @@ -672,8 +674,15 @@ impl Program { } } - pub fn compile(&self, dev: &Device, options: &str, headers: &[spirv::CLCHeader]) -> bool { - self.do_compile(dev, options, headers, &mut self.build_info()) + pub fn compile(&self, devs: &[&Device], options: &str, headers: &[spirv::CLCHeader]) -> bool { + let mut res = true; + for dev in devs { + res &= self.do_compile(dev, options, headers, &mut self.build_info()); + } + + debug_logging(self, devs); + + res } pub fn link( @@ -741,13 +750,17 @@ impl Program { // Pre build nir kernels build.rebuild_kernels(devs, false); - Arc::new(Self { + let res = Arc::new(Self { base: CLObjectBase::new(RusticlTypes::Program), context: context, devs: devs.to_owned(), src: ProgramSourceType::Linked, build: Mutex::new(build), - }) + }); + + debug_logging(&res, &devs); + + res } pub fn is_bin(&self) -> bool { @@ -786,3 +799,15 @@ impl Program { lock.spec_constants.insert(spec_id, val); } } + +/// Performs debug logging for the provided program and devices. +fn debug_logging(p: &Program, devs: &[&Device]) { + if Platform::dbg().program { + for dev in devs { + let msg = p.log(dev); + if !msg.is_empty() { + eprintln!("{}", msg); + } + } + } +}