Skip to content

Commit

Permalink
Adding test for iree-run-trace. (iree-org#6693)
Browse files Browse the repository at this point in the history
  • Loading branch information
benvanik authored Oct 20, 2021
1 parent cc4f173 commit 501781b
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 10 deletions.
3 changes: 1 addition & 2 deletions build_tools/cmake/iree_installed_test.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ function(iree_add_installed_test)
${ARGN}
)


add_test(
NAME
${_RULE_TEST_NAME}
Expand Down Expand Up @@ -60,7 +59,7 @@ function(iree_add_installed_test)

# Write the to the installed ctest file template.
set(_installed_ctest_input_file
"${CMAKE_BINARY_DIR}/iree_installed_tests.cmake.in")
"${CMAKE_BINARY_DIR}/iree_installed_tests.cmake.in")
get_property(_has_tests GLOBAL PROPERTY IREE_HAS_INSTALLED_TESTS)
if(NOT _has_tests)
# First time.
Expand Down
45 changes: 38 additions & 7 deletions build_tools/cmake/iree_lit_test.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,26 @@ function(iree_lit_test)

list(TRANSFORM _RULE_DATA REPLACE "^::" "${_PACKAGE_NS}::")
set(_DATA_DEP_PATHS)
foreach(_DATA_DEP ${_RULE_DATA})
list(APPEND _DATA_DEP_PATHS $<TARGET_FILE:${_DATA_DEP}>)
endforeach(_DATA_DEP)
foreach(_DATA_LABEL ${_RULE_DATA})
string(REPLACE "::" "_" _DATA_TARGET ${_DATA_LABEL})
string(REPLACE "::" "/" _FILE_PATH ${_DATA_LABEL})
set(_INPUT_PATH "${PROJECT_SOURCE_DIR}/${_FILE_PATH}")
set(_OUTPUT_PATH "${PROJECT_BINARY_DIR}/${_FILE_PATH}")
if(EXISTS "${_INPUT_PATH}")
# Create a target which copies the data file into the build directory.
# If this file is included in multiple rules, only create the target once.
if(NOT TARGET ${_DATA_TARGET})
add_custom_target(
${_DATA_TARGET} ALL
COMMAND
${CMAKE_COMMAND} -E copy_if_different ${_INPUT_PATH} ${_OUTPUT_PATH}
)
endif()
list(APPEND _DATA_DEP_PATHS "${_OUTPUT_PATH}")
else()
list(APPEND _DATA_DEP_PATHS "$<TARGET_FILE:${_DATA_TARGET}>")
endif()
endforeach()

iree_package_ns(_PACKAGE_NS)
string(REPLACE "::" "/" _PACKAGE_PATH ${_PACKAGE_NS})
Expand All @@ -78,12 +95,26 @@ function(iree_lit_test)
# Note that the data deps are not bundled: must be externally on the path.
bin/run_lit.${IREE_HOST_SCRIPT_EXT}
${_TEST_FILE_PATH}
${_DATA_DEP_PATHS}
WORKING_DIRECTORY
"${PROJECT_SOURCE_DIR}"
)
set_property(
TEST ${_NAME_PATH}
PROPERTY
REQUIRED_FILES
"${_TEST_FILE_PATH}"
"${_DATA_DEP_PATHS}"
)
set_property(TEST ${_NAME_PATH} PROPERTY REQUIRED_FILES "${_TEST_FILE_PATH}")

install(FILES ${_TEST_FILE_PATH}
DESTINATION "tests/${_PACKAGE_PATH}"
COMPONENT Tests
install(
FILES
"${_TEST_FILE_PATH}"
"${_DATA_DEP_PATHS}"
DESTINATION
"tests/${_PACKAGE_PATH}"
COMPONENT
Tests
)
# TODO(gcmn): Figure out how to indicate a dependency on _RULE_DATA being built
endfunction()
Expand Down
2 changes: 1 addition & 1 deletion iree/samples/vision/iree-run-mnist-module.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ int main(int argc, char** argv) {
}
iree_string_view_t image_path;
if (argc == 1) {
image_path = iree_make_cstring_view("mnist_test.png");
image_path = iree_make_cstring_view("iree/samples/vision/mnist_test.png");
} else {
image_path = iree_make_cstring_view(argv[1]);
}
Expand Down
3 changes: 3 additions & 0 deletions iree/tools/test/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ iree_lit_test_suite(
"iree-benchmark-module.mlir",
"iree-run-mlir.mlir",
"iree-run-module.mlir",
"iree-run-trace.mlir",
"multiple_args.mlir",
"multiple_exported_functions.mlir",
"repeated_return.mlir",
Expand All @@ -30,10 +31,12 @@ iree_lit_test_suite(
include = ["*.mlir"],
),
data = [
":iree-run-trace.yaml",
"//iree/tools:IreeFileCheck",
"//iree/tools:iree-benchmark-module",
"//iree/tools:iree-run-mlir",
"//iree/tools:iree-run-module",
"//iree/tools:iree-run-trace",
"//iree/tools:iree-translate",
],
tags = ["hostonly"],
Expand Down
3 changes: 3 additions & 0 deletions iree/tools/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,18 @@ iree_lit_test_suite(
"iree-benchmark-module.mlir"
"iree-run-mlir.mlir"
"iree-run-module.mlir"
"iree-run-trace.mlir"
"multiple_args.mlir"
"multiple_exported_functions.mlir"
"repeated_return.mlir"
"scalars.mlir"
DATA
::iree-run-trace.yaml
iree::tools::IreeFileCheck
iree::tools::iree-benchmark-module
iree::tools::iree-run-mlir
iree::tools::iree-run-module
iree::tools::iree-run-trace
iree::tools::iree-translate
LABELS
"hostonly"
Expand Down
11 changes: 11 additions & 0 deletions iree/tools/test/iree-run-trace.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// RUN: (iree-translate -iree-input-type=tosa -iree-hal-target-backends=vmvx -iree-mlir-to-vm-bytecode-module %s | iree-run-trace --driver=vmvx iree/tools/test/iree-run-trace.yaml) | IreeFileCheck %s

// CHECK: --- CALL[module.simple_mul] ---
// CHECK-NEXT: 4xf32=10 4 6 8
// CHECK-NEXT: --- CALL[module.simple_mul] ---
// CHECK-NEXT: 4xf32=4 10 18 28

func @simple_mul(%arg0: tensor<4xf32>, %arg1: tensor<4xf32>) -> tensor<4xf32> {
%0 = "tosa.mul"(%arg0, %arg1) {shift = 0 : i32} : (tensor<4xf32>, tensor<4xf32>) -> tensor<4xf32>
return %0 : tensor<4xf32>
}
46 changes: 46 additions & 0 deletions iree/tools/test/iree-run-trace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
type: context_load
---
type: module_load
module:
name: hal
type: builtin
---
type: module_load
module:
name: module
type: bytecode
path: <stdin>
---
type: call
function: module.simple_mul
args:
- !hal.buffer_view 4xf32=2 2 2 2
- type: hal.buffer_view
shape: 4
element_type: f32
contents: 5 2 3 4
results:
- !hal.buffer_view 4xf32=10 4 6 8
---
type: call
function: module.simple_mul
args:
- type: hal.buffer_view
shape:
- 4
element_type: 50331680
contents: !!binary |
AACAPwAAAEAAAEBAAACAQA==
- type: hal.buffer_view
shape:
- 4
element_type: 50331680
contents: !!binary |
AACAQAAAoEAAAMBAAADgQA==
results:
- type: hal.buffer_view
shape:
- 4
element_type: 50331680
contents: !!binary |
AACAQAAAIEEAAJBBAADgQQ==

0 comments on commit 501781b

Please sign in to comment.