Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow rust tvm build configuration through cargo features #8665

Merged
merged 2 commits into from
Aug 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions rust/tvm-rt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,55 @@ default = ["dynamic-linking"]
dynamic-linking = ["tvm-sys/dynamic-linking"]
static-linking = ["tvm-sys/static-linking"]
standalone = ["tvm-sys/runtime-only"]
runtime-only = ["tvm-sys/runtime-only"]
blas = ["ndarray/blas"]
# Enabling any of the following features is like setting the value to "ON" in config.cmake.
use-cuda = ["tvm-sys/use-cuda"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey @schell just wondering, is it possible to auto-generate this file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sure it's possible but it's definitely not standard. It would be a bespoke generator for sure.

This is the defacto Rust project declaration, so I think auto-generating it would be confusing for Rust contributors in the long run. I do agree that keeping these in sync with TVM proper will be a bit error prone though - especially since it has to happen in a number of crates in this repo. Unfortunately there doesn't seem to be any way to iterate over user-set features in Rust at the moment, which was what I was hoping to do to cut down on the boiler plate here.

Ultimately this approach is explicit, which is good - I learned about the CoreML support by adding these! But it does mean that the configurable features will always lag behind TVM proper.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can think about this kind of stuff in the Backlog @areusch

use-opencl = ["tvm-sys/use-opencl"]
use-vulkan = ["tvm-sys/use-vulkan"]
use-metal = ["tvm-sys/use-metal"]
use-rocm = ["tvm-sys/use-rocm"]
use-hexagon-device = ["tvm-sys/use-hexagon-device"]
use-rpc = ["tvm-sys/use-rpc"]
use-threads = ["tvm-sys/use-threads"]
use-llvm = ["tvm-sys/use-llvm"]
use-stackvm-runtime = ["tvm-sys/use-stackvm-runtime"]
use-graph-runtime = ["tvm-sys/use-graph-runtime"]
use-graph-runtime-debug = ["tvm-sys/use-graph-runtime-debug"]
use-openmp = ["tvm-sys/use-openmp"]
use-relay-debug = ["tvm-sys/use-relay-debug"]
use-rtti = ["tvm-sys/use-rtti"]
use-mscv-mt = ["tvm-sys/use-mscv-mt"]
use-micro = ["tvm-sys/use-micro"]
use-install-dev = ["tvm-sys/use-install-dev"]
hide-private-symbols = ["tvm-sys/hide-private-symbols"]
use-fallback-stl-map = ["tvm-sys/use-fallback-stl-map"]
use-ethosn = ["tvm-sys/use-ethosn"]
use-index-default-i64 = ["tvm-sys/use-index-default-i64"]
use-tf-tvmdsoop = ["tvm-sys/use-tf-tvmdsoop"]
use-byodt-posit = ["tvm-sys/use-byodt-posit"]
use-mkl = ["tvm-sys/use-mkl"]
use-mkldnn = ["tvm-sys/use-mkldnn"]
use-dnnl-codegen = ["tvm-sys/use-dnnl-codegen"]
use-cudnn = ["tvm-sys/use-cudnn"]
use-cublas = ["tvm-sys/use-cublas"]
use-thrust = ["tvm-sys/use-thrust"]
use-miopen = ["tvm-sys/use-miopen"]
use-rocblas = ["tvm-sys/use-rocblas"]
use-sort = ["tvm-sys/use-sort"]
use-nnpack = ["tvm-sys/use-nnpack"]
use-random = ["tvm-sys/use-random"]
use-micro-standalone-runtime = ["tvm-sys/use-micro-standalone-runtime"]
use-cpp-rpc = ["tvm-sys/use-cpp-rpc"]
use-tflite = ["tvm-sys/use-tflite"]
use-coreml = ["tvm-sys/use-coreml"]
use-target-onnx = ["tvm-sys/use-target-onnx"]
use-arm-compute-lib = ["tvm-sys/use-arm-compute-lib"]
use-arm-compute-lib-graph-runtime = ["tvm-sys/use-arm-compute-lib-graph-runtime"]
use-tensorrt-codegen = ["tvm-sys/use-tensorrt-codegen"]
use-tensorrt-runtime = ["tvm-sys/use-tensorrt-runtime"]
use-vitis-ai = ["tvm-sys/use-vitis-ai"]
build-static-runtime = ["tvm-sys/build-static-runtime"]

[dependencies]
thiserror = "^1.0"
Expand Down
49 changes: 48 additions & 1 deletion rust/tvm-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,53 @@ default = ["dynamic-linking"]
static-linking = []
dynamic-linking = []
runtime-only = []
# Enabling any of the following features is like setting the value to "ON" in config.cmake.
use-cuda = []
use-opencl = []
use-vulkan = []
use-metal = []
use-rocm = []
use-hexagon-device = []
use-rpc = []
use-threads = []
use-llvm = []
use-stackvm-runtime = []
use-graph-runtime = []
use-graph-runtime-debug = []
use-openmp = []
use-relay-debug = []
use-rtti = []
use-mscv-mt = []
use-micro = []
use-install-dev = []
hide-private-symbols = []
use-fallback-stl-map = []
use-ethosn = []
use-index-default-i64 = []
use-tf-tvmdsoop = []
use-byodt-posit = []
use-mkl = []
use-mkldnn = []
use-dnnl-codegen = []
use-cudnn = []
use-cublas = []
use-thrust = []
use-miopen = []
use-rocblas = []
use-sort = []
use-nnpack = []
use-random = []
use-micro-standalone-runtime = []
use-cpp-rpc = []
use-tflite = []
use-coreml = []
use-target-onnx = []
use-arm-compute-lib = []
use-arm-compute-lib-graph-runtime = []
use-tensorrt-codegen = []
use-tensorrt-runtime = []
use-vitis-ai = []
build-static-runtime = []

[dependencies]
thiserror = "^1.0"
Expand All @@ -38,4 +85,4 @@ enumn = "^0.1"
[build-dependencies]
bindgen = { version="0.57", default-features = false, features = ["runtime"] }
anyhow = "^1.0"
tvm-build = "0.1"
tvm-build = "0.2.1"
144 changes: 142 additions & 2 deletions rust/tvm-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@

extern crate bindgen;

use std::path::{Path, PathBuf};
use std::{path::{Path, PathBuf}, str::FromStr};

use anyhow::{Context, Result};
use tvm_build::BuildConfig;
use tvm_build::{BuildConfig, CMakeSetting};

/// The necessary information for detecting a TVM installation.
struct TVMInstall {
Expand Down Expand Up @@ -59,6 +59,146 @@ fn find_using_tvm_build() -> Result<TVMInstall> {
let mut build_config = BuildConfig::default();
build_config.repository = Some("https://github.com/apache/tvm".to_string());
build_config.branch = Some(option_env!("TVM_BRANCH").unwrap_or("main").into());

if cfg!(feature = "use-cuda") {
build_config.settings.use_cuda = CMakeSetting::from_str("on").ok();
}
if cfg!(feature = "use-opencl") {
build_config.settings.use_opencl = CMakeSetting::from_str("on").ok();
}
if cfg!(feature = "use-vulkan") {
build_config.settings.use_vulkan = CMakeSetting::from_str("on").ok();
}
if cfg!(feature = "use-rocm") {
build_config.settings.use_rocm = CMakeSetting::from_str("on").ok();
}
if cfg!(feature = "use-metal") {
build_config.settings.use_metal = CMakeSetting::from_str("on").ok();
}
if cfg!(feature = "use-hexagon-device") {
build_config.settings.use_hexagon_device = Some(true);
}
if cfg!(feature = "use-rpc") {
build_config.settings.use_rpc = Some(true);
}
if cfg!(feature = "use-threads") {
build_config.settings.use_threads = Some(true);
}
if cfg!(feature = "use-llvm") {
build_config.settings.use_llvm = CMakeSetting::from_str("on").ok();
}
if cfg!(feature = "use-stackvm-runtime") {
build_config.settings.use_stackvm_runtime = Some(true);
}
if cfg!(feature = "use-graph-runtime") {
build_config.settings.use_graph_runtime = Some(true);
}
if cfg!(feature = "use-graph-runtime-debug") {
build_config.settings.use_graph_runtime_debug = Some(true);
}
if cfg!(feature = "use-openmp") {
build_config.settings.use_openmp = Some(true);
}
if cfg!(feature = "use-relay-debug") {
build_config.settings.use_relay_debug = Some(true);
}
if cfg!(feature = "use-rtti") {
build_config.settings.use_rtti = Some(true);
}
if cfg!(feature = "use-mscv-mt") {
build_config.settings.use_mscv_mt = Some(true);
}
if cfg!(feature = "use-micro") {
build_config.settings.use_micro = Some(true);
}
if cfg!(feature = "use-install-dev") {
build_config.settings.use_install_dev = Some(true);
}
if cfg!(feature = "hide_private-symbols") {
build_config.settings.hide_private_symbols = Some(true);
}
if cfg!(feature = "use-fallback-stl-map") {
build_config.settings.use_fallback_stl_map = Some(true);
}
if cfg!(feature = "use-ethosn") {
build_config.settings.use_ethosn = Some(true);
}
if cfg!(feature = "use-index_default-i64") {
build_config.settings.use_index_default_i64 = Some(true);
}
if cfg!(feature = "use-tf-tvmdsoop") {
build_config.settings.use_tf_tvmdsoop = Some(true);
}
if cfg!(feature = "use-byodt-posit") {
build_config.settings.use_byodt_posit = Some(true);
}
if cfg!(feature = "use-mkl") {
build_config.settings.use_mkl = CMakeSetting::from_str("on").ok();
}
if cfg!(feature = "use-mkldnn") {
build_config.settings.use_mkldnn = CMakeSetting::from_str("on").ok();
}
if cfg!(feature = "use-dnnl-codegen") {
build_config.settings.use_dnnl_codegen = Some(true);
}
if cfg!(feature = "use-cudnn") {
build_config.settings.use_cudnn = Some(true);
}
if cfg!(feature = "use-cublas") {
build_config.settings.use_cublas = Some(true);
}
if cfg!(feature = "use-thrust") {
build_config.settings.use_thrust = Some(true);
}
if cfg!(feature = "use-miopen") {
build_config.settings.use_miopen = Some(true);
}
if cfg!(feature = "use-rocblas") {
build_config.settings.use_rocblas = Some(true);
}
if cfg!(feature = "use-sort") {
build_config.settings.use_sort = Some(true);
}
if cfg!(feature = "use-nnpack") {
build_config.settings.use_nnpack = Some(true);
}
if cfg!(feature = "use-random") {
build_config.settings.use_random = Some(true);
}
if cfg!(feature = "use-micro-standalone-runtime") {
build_config.settings.use_micro_standalone_runtime = Some(true);
}
if cfg!(feature = "use-cpp-rpc") {
build_config.settings.use_cpp_rpc = Some(true);
}
if cfg!(feature = "use-tflite") {
build_config.settings.use_tflite = Some(true);
}
if cfg!(feature = "use-coreml") {
build_config.settings.use_coreml = Some(true);
}
if cfg!(feature = "use-target-onnx") {
build_config.settings.use_target_onnx = Some(true);
}
if cfg!(feature = "use-arm-compute-lib") {
build_config.settings.use_arm_compute_lib = Some(true);
}
if cfg!(feature = "use-arm-compute-lib-graph-runtime") {
build_config.settings.use_arm_compute_lib_graph_runtime = CMakeSetting::from_str("on").ok();
}
if cfg!(feature = "use-tensorrt-codegen") {
build_config.settings.use_tensorrt_codegen = Some(true);
}
if cfg!(feature = "use-tensorrt-runtime") {
build_config.settings.use_tensorrt_runtime = CMakeSetting::from_str("on").ok();
}
if cfg!(feature = "use-vitis-ai") {
build_config.settings.use_vitis_ai = Some(true);
}
if cfg!(any(feature = "static-linking", feature = "build-static-runtime")) {
build_config.settings.build_static_runtime = Some(true);
}

let build_result = tvm_build::build(build_config)?;
let source_path = build_result.revision.source_path();
let build_path = build_result.revision.build_path();
Expand Down
46 changes: 46 additions & 0 deletions rust/tvm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,52 @@ dynamic-linking = ["tvm-rt/dynamic-linking"]
static-linking = ["tvm-rt/static-linking"]
blas = ["ndarray/blas"]
python = ["pyo3"]
# Enabling any of the following features is like setting the value to "ON" in config.cmake.
use-cuda = ["tvm-rt/use-cuda"]
use-opencl = ["tvm-rt/use-opencl"]
use-vulkan = ["tvm-rt/use-vulkan"]
use-metal = ["tvm-rt/use-metal"]
use-rocm = ["tvm-rt/use-rocm"]
use-hexagon-device = ["tvm-rt/use-hexagon-device"]
use-rpc = ["tvm-rt/use-rpc"]
use-threads = ["tvm-rt/use-threads"]
use-llvm = ["tvm-rt/use-llvm"]
use-stackvm-runtime = ["tvm-rt/use-stackvm-runtime"]
use-graph-runtime = ["tvm-rt/use-graph-runtime"]
use-graph-runtime-debug = ["tvm-rt/use-graph-runtime-debug"]
use-openmp = ["tvm-rt/use-openmp"]
use-relay-debug = ["tvm-rt/use-relay-debug"]
use-rtti = ["tvm-rt/use-rtti"]
use-mscv-mt = ["tvm-rt/use-mscv-mt"]
use-micro = ["tvm-rt/use-micro"]
use-install-dev = ["tvm-rt/use-install-dev"]
hide-private-symbols = ["tvm-rt/hide-private-symbols"]
use-fallback-stl-map = ["tvm-rt/use-fallback-stl-map"]
use-ethosn = ["tvm-rt/use-ethosn"]
use-index-default-i64 = ["tvm-rt/use-index-default-i64"]
use-tf-tvmdsoop = ["tvm-rt/use-tf-tvmdsoop"]
use-byodt-posit = ["tvm-rt/use-byodt-posit"]
use-mkl = ["tvm-rt/use-mkl"]
use-mkldnn = ["tvm-rt/use-mkldnn"]
use-dnnl-codegen = ["tvm-rt/use-dnnl-codegen"]
use-cudnn = ["tvm-rt/use-cudnn"]
use-cublas = ["tvm-rt/use-cublas"]
use-thrust = ["tvm-rt/use-thrust"]
use-miopen = ["tvm-rt/use-miopen"]
use-rocblas = ["tvm-rt/use-rocblas"]
use-sort = ["tvm-rt/use-sort"]
use-nnpack = ["tvm-rt/use-nnpack"]
use-random = ["tvm-rt/use-random"]
use-micro-standalone-runtime = ["tvm-rt/use-micro-standalone-runtime"]
use-cpp-rpc = ["tvm-rt/use-cpp-rpc"]
use-tflite = ["tvm-rt/use-tflite"]
use-coreml = ["tvm-rt/use-coreml"]
use-target-onnx = ["tvm-rt/use-target-onnx"]
use-arm-compute-lib = ["tvm-rt/use-arm-compute-lib"]
use-arm-compute-lib-graph-runtime = ["tvm-rt/use-arm-compute-lib-graph-runtime"]
use-tensorrt-codegen = ["tvm-rt/use-tensorrt-codegen"]
use-tensorrt-runtime = ["tvm-rt/use-tensorrt-runtime"]
use-vitis-ai = ["tvm-rt/use-vitis-ai"]

[dependencies.tvm-rt]
version = "0.1.0-alpha"
Expand Down