Skip to content

Commit

Permalink
add test and minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvedhmeshram committed Jun 17, 2024
1 parent 3d864d9 commit a11e419
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 14 deletions.
3 changes: 3 additions & 0 deletions build_tools/ci/cpu_comparison/run_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,9 @@ function run_test() {
run_test \
--test_file ${THIS_DIR}/test_files/matmul_int32.mlir

run_test \
--test_file ${THIS_DIR}/test_files/three_matmuls.mlir

run_test \
--name_prefix "matmul" \
--lhs_rhs_type "bf16" \
Expand Down
31 changes: 31 additions & 0 deletions build_tools/ci/cpu_comparison/test_files/three_matmuls.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// This test shows arbitory matmuls that would have producer consumer relationships
// across different dispatches running on CI.

// These lines are strictly required by the script which generates input data:
//
// input 32x32xf32
// input 32x32xf32
// input 32x4xf32
// input 4x32xf32

!A_TYPE = tensor<32x32xf32>
!B_TYPE = tensor<32x4xf32>
!C_TYPE = tensor <4x32xf32>
!D_TYPE = tensor <4x4xf32>
func.func @two_mm(%lhs : !A_TYPE,
%rhs : !A_TYPE, %rhs_2 : !B_TYPE, %lhs_2 : !C_TYPE) -> !D_TYPE {
%empty = tensor.empty() : !A_TYPE
%empty_2 = tensor.empty() : !B_TYPE
%empty_3 = tensor.empty() : !D_TYPE
%cst = arith.constant 0.0 : f32
%fill = linalg.fill ins(%cst : f32) outs(%empty : !A_TYPE) -> !A_TYPE
%fill_2 = linalg.fill ins(%cst : f32) outs(%empty_2 : !B_TYPE) -> !B_TYPE
%fill_3 = linalg.fill ins(%cst : f32) outs(%empty_3 : !D_TYPE) -> !D_TYPE
%2 = linalg.matmul ins(%lhs, %rhs : !A_TYPE, !A_TYPE)
outs(%fill : !A_TYPE) -> !A_TYPE
%3 = linalg.matmul ins(%2, %rhs_2 : !A_TYPE, !B_TYPE)
outs(%fill_2 : !B_TYPE) -> !B_TYPE
%4 = linalg.matmul ins(%lhs_2, %3 : !C_TYPE, !B_TYPE)
outs(%fill_3 : !D_TYPE) -> !D_TYPE
return %4 : !D_TYPE
}
18 changes: 4 additions & 14 deletions compiler/plugins/target/AMD-AIE/iree-amd-aie/Target/AIETarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ LogicalResult AIETargetBackend::serializeExecutable(
llvm::sys::path::append(npuInstPath,
entryPointNamesFb[ordinal] + ".npu.txt");

// Convert ordinal to hexadecimal string for xclbin kern id
// Convert ordinal to hexadecimal string for xclbin kernel id.
std::stringstream ss;
ss << "0x" << std::hex << ordinal + 10;
std::string ordinalHex = ss.str();
Expand Down Expand Up @@ -370,7 +370,7 @@ LogicalResult AIETargetBackend::serializeExecutable(
int result = llvm::sys::ExecuteAndWait(cmdArgs[0], cmdArgs, cmdEnvRefs);
if (result != 0 && AttemptingMerge) {
// we failed to create xclbin but maybe we failed becuase we were trying
// to merge the kerenel in exisiting kernel, try again to see if perhaps
// to merge the kerenel in exisiting xclbin, try again to see if perhaps
// we have success if we dont try to merge.
AttemptingMerge = false;
result =
Expand Down Expand Up @@ -400,18 +400,8 @@ LogicalResult AIETargetBackend::serializeExecutable(
asmInstrIndices[ordinal] = asmInstrRefs.size();
asmInstrRefs.push_back(
iree_amd_aie_hal_xrt_AsmInstDef_create(builder, npuInstrsVec));
/*
xclbinIn = openInputFile(xclbinPath, &errorMessage);
if (!xclbinIn) {
moduleOp.emitOpError() << "Failed to open xclbin file: " << errorMessage;
}
auto xclbinStringRef = builder.createString(xclbinIn->getBuffer());
xclbinIndices[ordinal] = xclbinRefs.size();
xclbinRefs.push_back(
iree_amd_aie_hal_xrt_XclbinDef_create(builder, xclbinStringRef));
*/
}
// write out the final xclbins to flatbuffer
// Write out the final xclbins to flatbuffer.
for (auto xclbinPath : xclbinPaths) {
llvm::outs() << "writing xclbin from path: " << xclbinPath << "\n";
std::string errorMessage;
Expand All @@ -424,7 +414,7 @@ LogicalResult AIETargetBackend::serializeExecutable(
iree_amd_aie_hal_xrt_XclbinDef_create(builder, xclbinStringRef));
}

// Serialize the executable to flatbuffer format
// Serialize the executable to flatbuffer format.
auto entryPointsRef = builder.createStringVec(entryPointNamesFb);

iree_amd_aie_hal_xrt_ExecutableDef_entry_points_add(builder, entryPointsRef);
Expand Down

0 comments on commit a11e419

Please sign in to comment.