rusticl: move debug logging to the end of the build step

Reviewed-by: Karol Herbst <kherbst@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/36497>
This commit is contained in:
Seán de Búrca
2025-08-02 10:36:37 -07:00
committed by Marge Bot
parent beadc1f93a
commit 5cb328d002
2 changed files with 30 additions and 23 deletions
+1 -19
View File
@@ -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<FuncProgramCB>,
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.
+29 -4
View File
@@ -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);
}
}
}
}