Skip to content
Open
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
7 changes: 7 additions & 0 deletions backends/aoti/slim/core/SlimTensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,13 @@ class SlimTensor {
return device().is_cpu();
}

/**
* Check if the tensor is on CUDA.
*/
bool is_cuda() const {
return device().is_cuda();
}

/**
* Check if the tensor is defined (has valid storage).
*/
Expand Down
3 changes: 2 additions & 1 deletion backends/aoti/slim/core/targets.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ def define_common_targets():
],
)

# Header-only library for SlimTensor (CPU-only for now)
runtime.cxx_library(
name = "slimtensor",
headers = [
Expand All @@ -37,6 +36,8 @@ def define_common_targets():
"//executorch/backends/aoti/slim/c10/core:sizes_and_strides",
"//executorch/backends/aoti/slim/util:array_ref_util",
"//executorch/backends/aoti/slim/util:size_util",
"//executorch/backends/aoti/slim/c10/cuda:exception",
"//executorch/backends/aoti/slim/cuda:guard",
"//executorch/runtime/platform:platform",
],
)
21 changes: 11 additions & 10 deletions backends/aoti/slim/core/test/targets.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,17 @@ def define_common_targets():
**backend_kwargs
)

runtime.cxx_test(
name = "test_slimtensor_basic",
srcs = [
"test_slimtensor_basic.cpp",
],
deps = [
"//executorch/backends/aoti/slim/core:slimtensor",
"//executorch/backends/aoti/slim/core:storage",
],
)
runtime.cxx_test(
name = "test_slimtensor_basic" + backend_suffix,
srcs = [
"test_slimtensor_basic.cpp",
],
deps = [
"//executorch/backends/aoti/slim/core:slimtensor",
"//executorch/backends/aoti/slim/core:storage",
],
**backend_kwargs
)

runtime.cxx_test(
name = "test_slimtensor_copy",
Expand Down
7 changes: 6 additions & 1 deletion backends/aoti/slim/core/test/test_slimtensor_basic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ namespace executorch::backends::aoti::slim {
inline std::vector<c10::Device> get_test_devices() {
std::vector<c10::Device> devices;
devices.push_back(CPU_DEVICE);
#ifdef CUDA_AVAILABLE
devices.push_back(DEFAULT_CUDA_DEVICE);
#endif
return devices;
}

Expand Down Expand Up @@ -52,7 +55,9 @@ INSTANTIATE_TEST_SUITE_P(
DeviceTests,
SlimTensorBasicDeviceTest,
::testing::ValuesIn(get_test_devices()),
[](const ::testing::TestParamInfo<c10::Device>& info) { return "CPU"; });
[](const ::testing::TestParamInfo<c10::Device>& info) {
return info.param.is_cuda() ? "CUDA" : "CPU";
});

// =============================================================================
// Constructor Tests (Device-Parameterized)
Expand Down
6 changes: 3 additions & 3 deletions backends/aoti/slim/factory/Empty.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace executorch::backends::aoti::slim {
/// @param sizes The sizes of each dimension.
/// @param strides The strides of each dimension.
/// @param dtype The scalar type of tensor elements.
/// @param device The target device (must be CPU).
/// @param device The target device.
/// @return A new SlimTensor with allocated but uninitialized storage.
inline SlimTensor empty_strided(
IntArrayRef sizes,
Expand All @@ -41,7 +41,7 @@ inline SlimTensor empty_strided(
///
/// @param sizes The sizes of each dimension.
/// @param dtype The scalar type of tensor elements.
/// @param device The target device (must be CPU).
/// @param device The target device.
/// @return A new SlimTensor with contiguous strides and uninitialized storage.
inline SlimTensor empty(
IntArrayRef sizes,
Expand All @@ -59,7 +59,7 @@ inline SlimTensor empty(
///
/// @param sizes The sizes of each dimension as an initializer list.
/// @param dtype The scalar type of tensor elements.
/// @param device The target device (must be CPU).
/// @param device The target device.
/// @return A new SlimTensor with contiguous strides and uninitialized storage.
inline SlimTensor empty(
std::initializer_list<int64_t> sizes,
Expand Down
37 changes: 28 additions & 9 deletions backends/aoti/slim/factory/test/targets.bzl
Original file line number Diff line number Diff line change
@@ -1,14 +1,33 @@
load("@fbcode_macros//build_defs/lib:re_test_utils.bzl", "re_test_utils")
load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime")

def get_backend_mode():
"""Get the supported backend mode of slimtensor."""
return ["cuda", "cpu"]

def define_common_targets():
"""Define test targets for SlimTensor factory module."""

runtime.cxx_test(
name = "test_empty",
srcs = [
"test_empty.cpp",
],
deps = [
"//executorch/backends/aoti/slim/factory:empty",
],
)
# GPU empty test with CUDA support
for backend_mode in get_backend_mode():
backend_suffix = "_" + backend_mode if backend_mode == "cuda" else ""

backend_kwargs = {
"external_deps": [("cuda", None, "cuda-lazy")],
"preprocessor_flags": ["-DCUDA_AVAILABLE=1"],
"keep_gpu_sections": True,
"remote_execution": re_test_utils.remote_execution(
platform = "gpu-remote-execution",
),
} if backend_mode == "cuda" else {}

runtime.cxx_test(
name = "test_empty" + backend_suffix,
srcs = [
"test_empty.cpp",
],
deps = [
"//executorch/backends/aoti/slim/factory:empty",
],
**backend_kwargs
)
Loading
Loading