Skip to content

Commit 88f5d10

Browse files
committed
address reviewer comments
Signed-off-by: Bangtian Liu <liubangtian@gmail.com>
1 parent 0ca2020 commit 88f5d10

2 files changed

Lines changed: 50 additions & 41 deletions

File tree

README.md

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -181,23 +181,7 @@ Pass custom IREE compiler flags using:
181181
- **C++ driver**: `FUSILLI_EXTRA_COMPILER_FLAGS` environment variable
182182
- **Python wrapper**: `--Xiree-compile` flag (which sets the environment variable internally)
183183

184-
**Single flag examples:**
185-
186-
C++ driver:
187-
```shell
188-
FUSILLI_EXTRA_COMPILER_FLAGS="--iree-opt-level=O3" \
189-
build/bin/benchmarks/fusilli_benchmark_driver --iter 100 \
190-
matmul -M 8192 -N 2048 -K 4096 --transA --a_type bf16 --b_type bf16 --out_type bf16
191-
```
192-
193-
Python wrapper:
194-
```shell
195-
python benchmarks/run_benchmark.py \
196-
--Xiree-compile="--iree-opt-level=O3" \
197-
-f commands.txt -o results.csv
198-
```
199-
200-
**Multiple flags:**
184+
**Examples:**
201185

202186
C++ driver (space-separated in one string):
203187
```shell

tests/test_compile_session.cpp

Lines changed: 49 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,43 @@
1313
#include <catch2/matchers/catch_matchers_string.hpp>
1414

1515
#include <algorithm>
16+
#include <cassert>
1617
#include <filesystem>
18+
#include <fstream>
1719
#include <string>
1820
#include <vector>
1921

2022
using namespace fusilli;
2123

2224
static std::string kGraphName = "test_compile_session";
2325

26+
// Returns the path to a shared tuning spec file for tests. The file is created
27+
// once and persists for the process lifetime because IREE caches parsed tuning
28+
// specs on the dialect instance keyed by path, and the tuning spec flag itself
29+
// is a process-wide static. Deleting the file would break subsequent
30+
// compilations that hit the cached path.
31+
static std::filesystem::path getTestTuningSpecPath() {
32+
static std::filesystem::path path = [] {
33+
std::filesystem::path dir =
34+
std::filesystem::temp_directory_path() / "fusilli_test_tuning_specs";
35+
std::filesystem::create_directories(dir);
36+
std::filesystem::path p = dir / "tuning_spec.mlir";
37+
std::ofstream ofs(p);
38+
assert(ofs.is_open() && "Failed to create test tuning spec file");
39+
ofs << R"(
40+
module attributes {transform.with_named_sequence} {
41+
transform.named_sequence @__kernel_config(%arg0: !transform.any_op {transform.consumed})
42+
-> !transform.any_op attributes {iree_codegen.tuning_spec_entrypoint} {
43+
transform.yield %arg0 : !transform.any_op
44+
}
45+
}
46+
)";
47+
ofs.close();
48+
return p;
49+
}();
50+
return path;
51+
}
52+
2453
TEST_CASE("CompileContext::create successfully loads library",
2554
"[CompileContext]") {
2655
// Get the shared compiler context.
@@ -530,10 +559,9 @@ TEST_CASE("CompileSession::addFlag with tuning spec path",
530559
FUSILLI_REQUIRE_ASSIGN(CompileSession session,
531560
context->createSession(handle));
532561

533-
std::string tuningSpecPath = "/tmp/test_tuning_spec.mlir";
534-
535562
ErrorObject result =
536-
session.addFlag("--iree-codegen-tuning-spec-path=" + tuningSpecPath);
563+
session.addFlag("--iree-codegen-tuning-spec-path=" +
564+
getTestTuningSpecPath().generic_string());
537565
FUSILLI_REQUIRE_OK(result);
538566

539567
const std::vector<std::string> &args = session.getArgs();
@@ -553,35 +581,32 @@ TEST_CASE("CompileSession::compile with tuning spec",
553581
FUSILLI_REQUIRE_ASSIGN(CompileSession session,
554582
context->createSession(handle));
555583

556-
// Create a minimal no-op tuning spec.
557-
FUSILLI_REQUIRE_ASSIGN(
558-
CacheFile tuningSpec,
559-
CacheFile::create(kGraphName, "test_tuning_spec.mlir", /*remove=*/true));
560-
561-
std::string tuningSpecContent = R"(
562-
module attributes {transform.with_named_sequence} {
563-
transform.named_sequence @__kernel_config(%arg0: !transform.any_op {transform.consumed})
564-
-> !transform.any_op attributes {iree_codegen.tuning_spec_entrypoint} {
565-
transform.yield %arg0 : !transform.any_op
566-
}
567-
}
568-
)";
569-
FUSILLI_REQUIRE_OK(tuningSpec.write(tuningSpecContent));
570-
571584
FUSILLI_REQUIRE_OK(session.addFlag("--iree-codegen-tuning-spec-path=" +
572-
tuningSpec.path.string()));
585+
getTestTuningSpecPath().generic_string()));
586+
587+
// Create input/output files in cache (these will auto-cleanup with
588+
// remove=true).
589+
std::string graphName = "test_compile_session_with_tuning_spec";
573590
FUSILLI_REQUIRE_ASSIGN(
574591
CacheFile input,
575-
CacheFile::create(kGraphName, "input_with_spec.mlir", /*remove=*/true));
592+
CacheFile::create(graphName, "input.mlir", /*remove=*/true));
576593
FUSILLI_REQUIRE_ASSIGN(
577594
CacheFile output,
578-
CacheFile::create(kGraphName, "output_with_spec.vmfb", /*remove=*/true));
595+
CacheFile::create(graphName, "output.vmfb", /*remove=*/true));
579596

580-
std::string mlirContent = getSimpleMLIRModule();
597+
// Write a simple MLIR module to the input file.
598+
std::string mlirContent = R"(
599+
module {
600+
func.func @tuning_spec_test(%arg0: tensor<3x3xf32>, %arg1: tensor<3x3xf32>) -> tensor<3x3xf32> {
601+
%0 = arith.mulf %arg0, %arg1 : tensor<3x3xf32>
602+
return %0 : tensor<3x3xf32>
603+
}
604+
}
605+
)";
581606
FUSILLI_REQUIRE_OK(input.write(mlirContent));
582607

583-
ErrorObject compileResult =
584-
session.compile(input.path.string(), output.path.string());
608+
ErrorObject compileResult = session.compile(input.path.generic_string(),
609+
output.path.generic_string());
585610
FUSILLI_REQUIRE_OK(compileResult);
586611
REQUIRE(std::filesystem::exists(output.path));
587612
REQUIRE(std::filesystem::file_size(output.path) > 0);

0 commit comments

Comments
 (0)