Skip to content

Commit

Permalink
Merge pull request #9443 from google/benvanik-device-flags
Browse files Browse the repository at this point in the history
Replacing `--driver=` with `--device=` and adding list flags.
  • Loading branch information
benvanik authored Jun 10, 2022
2 parents 33a7caa + bba52ae commit 379c2e4
Show file tree
Hide file tree
Showing 57 changed files with 901 additions and 169 deletions.
2 changes: 1 addition & 1 deletion build_tools/bazel/iree_check_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def iree_check_test(
native_test(
name = name,
args = [
"--driver=%s" % driver,
"--device=%s" % driver,
"$(location :%s)" % bytecode_module_name,
] + runner_args,
data = [":%s" % bytecode_module_name],
Expand Down
2 changes: 1 addition & 1 deletion build_tools/bazel/iree_trace_runner_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def iree_trace_runner_test(
native_test(
name = name,
args = [
"--driver=%s" % driver,
"--device=%s" % driver,
"$(location :%s)" % trace,
] + runner_args,
data = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def parse_latency_from_output(self, output: str) -> float:

def generate_benchmark_command(self) -> list[str]:
command = super().generate_benchmark_command()
command.append("--driver=" + self.driver)
command.append("--device=" + self.driver)
command.append("--task_topology_group_count=" + str(self.num_threads))
command.append("--benchmark_repetitions=" + str(self.num_runs))
return command
2 changes: 1 addition & 1 deletion build_tools/cmake/iree_benchmark_suite.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ function(iree_benchmark_suite)
COMMAND
"${Python3_EXECUTABLE}" "${IREE_ROOT_DIR}/build_tools/scripts/generate_flagfile.py"
--module_file="${_MODULE_FILE_FLAG}"
--driver=${_RULE_DRIVER}
--device=${_RULE_DRIVER}
--entry_function=${_MODULE_ENTRY_FUNCTION}
--function_inputs=${_MODULE_FUNCTION_INPUTS}
"${_ADDITIONAL_ARGS_CL}"
Expand Down
6 changes: 3 additions & 3 deletions build_tools/cmake/iree_native_test.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ include(CMakeParseArguments)
#
# Parameters:
# NAME: name of target
# DRIVER: If specified, will pass --driver=DRIVER to the test binary and adds
# DRIVER: If specified, will pass --device=DRIVER to the test binary and adds
# a driver label to the test.
# TEST_INPUT_FILE_ARG: If specified, the input file will be added to DATA and
# its device path appended to ARGS. Note that the device path may be
Expand All @@ -24,7 +24,7 @@ include(CMakeParseArguments)
# a separate device (e.g. Android), these files will be pushed to the
# device. TEST_INPUT_FILE_ARG is automatically added if specified.
# ARGS: additional arguments passed to the test binary. TEST_INPUT_FILE_ARG and
# --driver=DRIVER are automatically added if specified.
# --device=DRIVER are automatically added if specified.
# SRC: binary target to run as the test.
# LABELS: Additional labels to apply to the test. The package path is added
# automatically.
Expand Down Expand Up @@ -69,7 +69,7 @@ function(iree_native_test)

# If driver was specified, add the corresponding test arg and label.
if(DEFINED _RULE_DRIVER)
list(APPEND _RULE_ARGS "--driver=${_RULE_DRIVER}")
list(APPEND _RULE_ARGS "--device=${_RULE_DRIVER}")
list(APPEND _RULE_LABELS "driver=${_RULE_DRIVER}")
endif()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
(os.getenv("QEMU_RV64_BIN"), os.getenv("RISCV_TOOLCHAIN_ROOT")))

config.environment["TEST_MODULE_CMD"] = (
"%s %s/tools/iree-run-module --driver=local-task" %
"%s %s/tools/iree-run-module --device=local-task" %
(config.environment["TEST_CMD"], os.getenv("BUILD_RISCV_DIR")))

config.test_exec_root = os.getenv("BUILD_RISCV_DIR") + \
Expand Down
8 changes: 4 additions & 4 deletions build_tools/scripts/generate_flagfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ def parse_arguments():
required=True,
metavar="<module-file>",
help="The name of the module file")
parser.add_argument("--driver",
parser.add_argument("--device",
type=str,
required=True,
metavar="<driver>",
help="The name of the IREE driver")
metavar="<device>",
help="The name of the HAL device")
parser.add_argument("--entry_function",
type=str,
required=True,
Expand All @@ -50,7 +50,7 @@ def parse_arguments():

def main(args):
lines = [
f"--driver={args.driver}", f"--module_file={args.module_file}",
f"--device={args.device}", f"--module_file={args.module_file}",
f"--entry_function={args.entry_function}"
]
lines.extend([
Expand Down
2 changes: 1 addition & 1 deletion docs/developers/design_docs/cuda_backend.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ $ ../iree-build/tools/iree-compile \

# Run the module through CUDA HAL backend.
$ ../iree-build/tools/iree-run-module \
--driver=cuda \
--device=cuda \
--module_file=/tmp/mhlo-add.vmfb \
--entry_function=add \
--function_input="4xf32=[1 2 3 4]" \
Expand Down
6 changes: 3 additions & 3 deletions docs/developers/developing_iree/benchmarking.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ and then benchmark an exported function in that module:
```shell
$ bazel run //tools:iree-benchmark-module -- \
--module_file=/tmp/module.fb \
--driver=local-task \
--device=local-task \
--entry_function=abs \
--function_input=f32=-2
```
Expand Down Expand Up @@ -78,7 +78,7 @@ Now we'll actually invoke the binary:
```shell
$ ./bazel-bin/tools/iree-benchmark-module \
--module_file=/tmp/module.fb \
--driver=local-task \
--device=local-task \
--entry_function=abs \
--function_input=f32=-2
```
Expand Down Expand Up @@ -122,7 +122,7 @@ in that module:
```shell
$ build/tools/iree-benchmark-module
--module_file=/tmp/fullyconnected.vmfb
--driver=local-task
--device=local-task
```

If no `entry_function` is specified, `iree-benchmark-module` will register a
Expand Down
4 changes: 2 additions & 2 deletions docs/developers/developing_iree/developer_overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ above on IREE's VMVX driver:
```shell
$ ../iree-build/tools/iree-run-module \
--module_file=/tmp/simple_abs_vmvx.vmfb \
--driver=local-task \
--device=local-task \
--entry_function=abs \
--function_input=f32=-2
```
Expand All @@ -165,7 +165,7 @@ $ ../iree-build/tools/iree-compile \
```shell
$ ../iree-build/tools/iree-check-module \
/tmp/abs.vmfb \
--driver=local-task
--device=local-task
```

### iree-run-mlir
Expand Down
4 changes: 2 additions & 2 deletions docs/developers/developing_iree/e2e_benchmarking.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ on VMVX run:
```shell
$ tools/iree-benchmark-module \
--module_file=/tmp/iree/modules/MatrixOpsStaticModule/iree_vmvx/compiled.vmfb \
--driver=local-task \
--device=local-task \
--entry_function=matmul_lhs_batch \
--function_input=256x64x32xf32=2 \
--function_input=32x16xf32=3
Expand Down Expand Up @@ -221,7 +221,7 @@ $ adb push /tmp/iree/modules/MatrixOpsStaticModule/iree_vmvx/* \
```shell
$ adb shell /data/local/tmp/iree-benchmark-module \
--module_file="/data/local/tmp/MatrixOpsStaticModule/iree_vmvx/compiled.vmfb" \
--driver=local-task \
--device=local-task \
--entry_function=matmul_lhs_batch \
--function_input=256x64x32xf32=2 \
--function_input=32x16xf32=3
Expand Down
6 changes: 3 additions & 3 deletions docs/developers/developing_iree/profiling_cpu_events.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ subsequent commands analyzing the profile. Example:
```shell
perf record -o /tmp/perf.data \
./tools/iree-benchmark-module \
--driver=local-task \
--device=local-task \
... command-line arguments of iree-benchmark-module as usual ...
```

Expand All @@ -73,7 +73,7 @@ by, with the `-e` flag. For instance, to sample by L1 cache misses, one may do:
```shell
perf record -o /tmp/perf.data -e L1-dcache-load-misses \
./tools/iree-benchmark-module \
--driver=local-task \
--device=local-task \
... command-line arguments of iree-benchmark-module as usual ...
```

Expand Down Expand Up @@ -150,7 +150,7 @@ First, we record on the device:
adb shell \
simpleperf record -e raw-l1d-cache-refill -o /data/local/tmp/perf.data \
/data/local/tmp/iree-benchmark-module \
--driver=local-task \
--device=local-task \
... command-line arguments of iree-benchmark-module as usual ...
```

Expand Down
2 changes: 1 addition & 1 deletion docs/developers/developing_iree/profiling_vulkan_gpu.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ $ /path/to/iree/build/tools/iree-compile -- \
# Then package the Android app
$ /path/to/iree/source/tools/android/run_module_app/build_apk.sh \
./build-apk \
--driver vulkan \
--device vulkan \
--module_file /tmp/mhlo-dot.vmfb \
--entry_function dot \
--function_input=...
Expand Down
2 changes: 1 addition & 1 deletion docs/developers/developing_iree/profiling_with_tracy.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ Example:

```shell
TRACY_NO_EXIT=1 /data/local/tmp/iree-benchmark-module \
--driver=local-task \
--device=local-task \
--module_file=/data/local/tmp/android_module.fbvm \
--entry_function=serving_default \
--function_input=1x384xi32 \
Expand Down
2 changes: 1 addition & 1 deletion docs/website/docs/building-from-source/android.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ adb push /tmp/simple_abs_vmvx.vmfb /data/local/tmp/
Run the tool:

``` shell
adb shell /data/local/tmp/iree-run-module --driver=local-task \
adb shell /data/local/tmp/iree-run-module --device=local-task \
--module_file=/data/local/tmp/simple_abs_vmvx.vmfb \
--entry_function=abs \
--function_input="f32=-5"
Expand Down
4 changes: 2 additions & 2 deletions docs/website/docs/building-from-source/riscv.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ ${QEMU_BIN} \
-cpu rv64 \
-L ${RISCV_TOOLCHAIN_ROOT}/sysroot/ \
../iree-build-riscv/tools/iree-run-module \
--driver=local-task \
--device=local-task \
--module_file=/tmp/simple_abs_vmvx.vmfb \
--entry_function=abs \
--function_input=f32=-5
Expand Down Expand Up @@ -163,7 +163,7 @@ ${QEMU_BIN} \
-cpu rv64,x-v=true,x-k=true,vlen=256,elen=64,vext_spec=v1.0 \
-L ${RISCV_TOOLCHAIN_ROOT}/sysroot/ \
../iree-build-riscv/tools/iree-run-module \
--driver=local-task \
--device=local-task \
--module_file=mobilenet_cpu.vmfb \
--entry_function=predict \
--function_input="1x224x224x3xf32=0"
Expand Down
2 changes: 1 addition & 1 deletion docs/website/docs/deployment-configurations/cpu.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ In the build directory, run the following command:

``` shell hl_lines="2"
tools/iree-run-module \
--driver=local-task \
--device=local-task \
--module_file=mobilenet_cpu.vmfb \
--entry_function=predict \
--function_input="1x224x224x3xf32=0"
Expand Down
4 changes: 2 additions & 2 deletions docs/website/docs/deployment-configurations/gpu-cuda-rocm.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ In the build directory, run the following command:

``` shell hl_lines="2"
tools/iree-run-module \
--driver=cuda \
--device=cuda \
--module_file=mobilenet-cuda.vmfb \
--entry_function=predict \
--function_input="1x224x224x3xf32=0"
Expand All @@ -168,7 +168,7 @@ In the build directory, run the following command:

``` shell hl_lines="2"
tools/iree-run-module \
--driver=rocm \
--device=rocm \
--module_file=mobilenet-rocm.vmfb \
--entry_function=predict \
--function_input="1x224x224x3xf32=0"
Expand Down
2 changes: 1 addition & 1 deletion docs/website/docs/deployment-configurations/gpu-vulkan.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ In the build directory, run the following command:

``` shell hl_lines="2"
tools/iree-run-module \
--driver=vulkan \
--device=vulkan \
--module_file=mobilenet-vulkan.vmfb \
--entry_function=predict \
--function_input="1x224x224x3xf32=0"
Expand Down
19 changes: 16 additions & 3 deletions experimental/rocm/rocm_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ static iree_status_t iree_hal_rocm_driver_query_available_devices(
uint8_t* buffer_ptr =
(uint8_t*)device_infos + device_count * sizeof(iree_hal_device_info_t);
for (iree_host_size_t i = 0; i < device_count; ++i) {
hipDevice_t device;
iree_status_t status = ROCM_RESULT_TO_STATUS(
&driver->syms, hipDeviceGet(&device, i), "hipDeviceGet");
hipDevice_t device = 0;
status = ROCM_RESULT_TO_STATUS(&driver->syms, hipDeviceGet(&device, i),
"hipDeviceGet");
if (!iree_status_is_ok(status)) break;
buffer_ptr = iree_hal_rocm_populate_device_info(
device, &driver->syms, buffer_ptr, &device_infos[i]);
Expand All @@ -152,6 +152,18 @@ static iree_status_t iree_hal_rocm_driver_query_available_devices(
return status;
}

static iree_status_t iree_hal_rocm_driver_dump_device_info(
iree_hal_driver_t* base_driver, iree_hal_device_id_t device_id,
iree_string_builder_t* builder) {
iree_hal_rocm_driver_t* driver = iree_hal_rocm_driver_cast(base_driver);
hipDevice_t device = (hipDevice_t)device_id;
if (!device) return iree_ok_status();
// TODO: dump detailed device info.
(void)driver;
(void)device;
return iree_ok_status();
}

static iree_status_t iree_hal_rocm_driver_select_default_device(
iree_hal_rocm_dynamic_symbols_t* syms, int default_device_index,
iree_allocator_t host_allocator, hipDevice_t* out_device) {
Expand Down Expand Up @@ -219,6 +231,7 @@ static iree_status_t iree_hal_rocm_driver_create_device_by_path(
static const iree_hal_driver_vtable_t iree_hal_rocm_driver_vtable = {
.destroy = iree_hal_rocm_driver_destroy,
.query_available_devices = iree_hal_rocm_driver_query_available_devices,
.dump_device_info = iree_hal_rocm_driver_dump_device_info,
.create_device_by_id = iree_hal_rocm_driver_create_device_by_id,
.create_device_by_path = iree_hal_rocm_driver_create_device_by_path,
};
12 changes: 6 additions & 6 deletions experimental/web/run_native_benchmarks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ IREE_BENCHMARK_MODULE_PATH=iree-benchmark-module
echo "Benchmarking DeepLabV3..."
"${IREE_BENCHMARK_MODULE_PATH?}" \
--module_file=./deeplabv3_native.vmfb \
--driver=local-task \
--device=local-task \
--task_topology_group_count=1 \
--entry_function=main \
--function_input=1x257x257x3xf32 \
Expand All @@ -44,7 +44,7 @@ echo ""
echo "Benchmarking MobileSSD..."
"${IREE_BENCHMARK_MODULE_PATH?}" \
--module_file=./mobile_ssd_v2_float_coco_native.vmfb \
--driver=local-task \
--device=local-task \
--task_topology_group_count=1 \
--entry_function=main \
--function_input=1x320x320x3xf32 \
Expand All @@ -54,7 +54,7 @@ echo ""
echo "Benchmarking PoseNet..."
"${IREE_BENCHMARK_MODULE_PATH?}" \
--module_file=./posenet_native.vmfb \
--driver=local-task \
--device=local-task \
--task_topology_group_count=1 \
--entry_function=main \
--function_input=1x353x257x3xf32 \
Expand All @@ -64,7 +64,7 @@ echo ""
echo "Benchmarking MobileBertSquad..."
"${IREE_BENCHMARK_MODULE_PATH?}" \
--module_file=./mobilebertsquad_native.vmfb \
--driver=local-task \
--device=local-task \
--task_topology_group_count=1 \
--entry_function=main \
--function_input=1x384xi32 \
Expand All @@ -76,7 +76,7 @@ echo ""
echo "Benchmarking MobileNetV2..."
"${IREE_BENCHMARK_MODULE_PATH?}" \
--module_file=./mobilenet_v2_1.0_224_native.vmfb \
--driver=local-task \
--device=local-task \
--task_topology_group_count=1 \
--entry_function=main \
--function_input=1x224x224x3xf32 \
Expand All @@ -86,7 +86,7 @@ echo ""
echo "Benchmarking MobileNetV3Small..."
"${IREE_BENCHMARK_MODULE_PATH?}" \
--module_file=./MobileNetV3SmallStaticBatch_native.vmfb \
--driver=local-task \
--device=local-task \
--task_topology_group_count=1 \
--entry_function=main \
--function_input=1x224x224x3xf32 \
Expand Down
2 changes: 1 addition & 1 deletion experimental/web/testing/parse_test_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def parse_ctest_dump(ctest_dump_path, build_dir):

# Parse the 'command' list into the source file and its arguments.
# /path/to/test_runner.js # such as iree-check-module.js or test.js
# arg 1 # such as --driver=local-task
# arg 1 # such as --device=local-task
# arg 2 # such as check_vmvx_op.mlir_module.vmfb
test_source_absolute_path = test["command"][0]
parsed_test["sourceFile"] = get_normalized_relative_path(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ def serialize(self, trace_dir: str) -> None:
serialized_inputs = self.calls[0].serialized_inputs
flagfile = [
f"--module_file={compiled_path}",
f"--driver={self.backend_driver}",
f"--device={self.backend_driver}",
f"--entry_function={entry_function}",
] + [f"--function_input={input}" for input in serialized_inputs]
with open(os.path.join(trace_dir, "flagfile"), "w") as f:
Expand Down
Loading

0 comments on commit 379c2e4

Please sign in to comment.