From 0ac163e4b73a483d003e8b3e470916117ea44cf3 Mon Sep 17 00:00:00 2001 From: NiccoloN Date: Fri, 10 Apr 2026 19:02:20 +0200 Subject: [PATCH] keep pimsim-nn happy --- .../src/lib/json_to_instruction/json_to_executor.rs | 2 +- src/PIM/Compiler/PimCodeGen.cpp | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/backend-simulators/pim/pim-simulator/src/lib/json_to_instruction/json_to_executor.rs b/backend-simulators/pim/pim-simulator/src/lib/json_to_instruction/json_to_executor.rs index 150b957..cc7d507 100644 --- a/backend-simulators/pim/pim-simulator/src/lib/json_to_instruction/json_to_executor.rs +++ b/backend-simulators/pim/pim-simulator/src/lib/json_to_instruction/json_to_executor.rs @@ -18,7 +18,7 @@ pub fn json_to_executor<'a>( mut cores: impl Iterator, ) -> Executable { let cell_precision = config.get("cell_precision").unwrap().as_i64().unwrap() as i32; - let core_cnt = config.get("core_cnt").unwrap().as_i64().unwrap() as i32; + let core_cnt = config.get("core_cnt").unwrap().as_i64().unwrap() as i32 - 1; let xbar_count = config.get("xbar_array_count").unwrap().as_i64().unwrap() as i32; let xbar_size = config.get("xbar_size").unwrap().as_array().unwrap(); let rows_crossbar = xbar_size[0].as_i64().unwrap() as i32; diff --git a/src/PIM/Compiler/PimCodeGen.cpp b/src/PIM/Compiler/PimCodeGen.cpp index 7006869..3e88a69 100644 --- a/src/PIM/Compiler/PimCodeGen.cpp +++ b/src/PIM/Compiler/PimCodeGen.cpp @@ -651,7 +651,9 @@ static OnnxMlirCompilerErrorCodes writeConfigJson(func::FuncOp funcOp, json::Object xbarsPerArrayGroup, StringRef outputDirPath) { json::Object configJson; - configJson["core_cnt"] = coreCount; + + // +1 because pimsim-nn also considers the host as a core + configJson["core_cnt"] = coreCount + 1; // TODO: Should this be based on the floating point type used in the model? // The 2 following values determine the bitwidth of the vectors' elements: bitwidth = adc_count * cell_precision @@ -718,7 +720,8 @@ OnnxMlirCompilerErrorCodes onnx_mlir::compileToPimJson(ModuleOp& moduleOp, std:: errs() << "Error while opening host core file `" << outputHostCorePath << "`: " << errorCode.message() << '\n'; return InvalidOutputFileAccess; } - hostFileStream << "[]"; + // The host core json contains 2 random instructions, just to make pimsim-nn happy + hostFileStream << "[{\"imm\":0,\"op\":\"sldi\",\"rd\":0},{\"imm\":0,\"op\":\"sldi\",\"rd\":0}]"; hostFileStream.close(); // For each core, specify the number of crossbar per array group.