From a23af19f86c47c81020fe3964b7f07a4a0cc7e4b Mon Sep 17 00:00:00 2001 From: Karol Herbst Date: Fri, 18 Mar 2022 16:24:30 +0100 Subject: [PATCH] rusticl/kernel: sweep nir to reduce peak memory usage Signed-off-by: Karol Herbst Acked-by: Alyssa Rosenzweig Part-of: --- src/gallium/frontends/rusticl/core/kernel.rs | 3 +++ src/gallium/frontends/rusticl/mesa/compiler/nir.rs | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/src/gallium/frontends/rusticl/core/kernel.rs b/src/gallium/frontends/rusticl/core/kernel.rs index 05037c6f08e..8d65119d880 100644 --- a/src/gallium/frontends/rusticl/core/kernel.rs +++ b/src/gallium/frontends/rusticl/core/kernel.rs @@ -174,6 +174,8 @@ fn lower_and_optimize_nir_pre_inputs(nir: &mut NirShader, lib_clc: &NirShader) { } {} nir.inline(lib_clc); nir.remove_non_entrypoints(); + // that should free up tons of memory + nir.sweep_mem(); while { let mut progress = false; progress |= nir.pass0(nir_copy_prop); @@ -326,6 +328,7 @@ fn lower_and_optimize_nir_late( nir.pass1(nir_lower_convert_alu_types, None); nir.pass0(nir_opt_dce); dev.screen.finalize_nir(nir); + nir.sweep_mem(); res } diff --git a/src/gallium/frontends/rusticl/mesa/compiler/nir.rs b/src/gallium/frontends/rusticl/mesa/compiler/nir.rs index ba1e8caef7f..7737c23687b 100644 --- a/src/gallium/frontends/rusticl/mesa/compiler/nir.rs +++ b/src/gallium/frontends/rusticl/mesa/compiler/nir.rs @@ -81,6 +81,10 @@ impl NirShader { unsafe { nir_shader_clone(ptr::null_mut(), self.nir.as_ptr()) } } + pub fn sweep_mem(&self) { + unsafe { nir_sweep(self.nir.as_ptr()) } + } + pub fn pass0(&mut self, pass: unsafe extern "C" fn(*mut nir_shader) -> R) -> R { unsafe { pass(self.nir.as_ptr()) } }