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
2 changes: 1 addition & 1 deletion backends/aoti/common_shims_slim.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
// CUDA backend (SlimTensor) and other backends like MPS (ETensor).
// The caller determines which path is used by defining CUDA_AVAILABLE.
#ifdef CUDA_AVAILABLE
#include <executorch/backends/aoti/slim/core/SlimTensor.h>
#include <executorch/backends/aoti/slim/core/slim_tensor.h>
#else
#include <executorch/runtime/core/exec_aten/exec_aten.h>
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
#include <executorch/backends/aoti/slim/c10/core/Device.h>
#include <executorch/backends/aoti/slim/c10/core/ScalarType.h>
#include <executorch/backends/aoti/slim/c10/core/SizesAndStrides.h>
#include <executorch/backends/aoti/slim/core/Storage.h>
#include <executorch/backends/aoti/slim/util/ArrayRefUtil.h>
#include <executorch/backends/aoti/slim/util/SizeUtil.h>
#include <executorch/backends/aoti/slim/core/storage.h>
#include <executorch/backends/aoti/slim/util/array_ref_util.h>
#include <executorch/backends/aoti/slim/util/size_util.h>
#include <executorch/runtime/platform/assert.h>

namespace executorch::backends::aoti::slim {
Expand Down Expand Up @@ -568,4 +568,4 @@ class SlimTensor {

// Include view operations implementations (must be after SlimTensor class
// definition)
#include <executorch/backends/aoti/slim/core/SlimTensorView-incl.h>
#include <executorch/backends/aoti/slim/core/slim_tensor_view_incl.h>
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#pragma once

#include <executorch/backends/aoti/slim/c10/core/WrapDimMinimal.h>
#include <executorch/backends/aoti/slim/util/ArrayRefUtil.h>
#include <executorch/backends/aoti/slim/util/array_ref_util.h>

namespace executorch::backends::aoti::slim {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

#include <executorch/backends/aoti/slim/c10/core/Device.h>
#include <executorch/backends/aoti/slim/c10/core/ScalarType.h>
#include <executorch/backends/aoti/slim/util/ArrayRefUtil.h>
#include <executorch/backends/aoti/slim/util/SharedPtr.h>
#include <executorch/backends/aoti/slim/util/SizeUtil.h>
#include <executorch/backends/aoti/slim/util/array_ref_util.h>
#include <executorch/backends/aoti/slim/util/shared_ptr.h>
#include <executorch/backends/aoti/slim/util/size_util.h>
#include <executorch/runtime/platform/assert.h>
#include <executorch/runtime/platform/log.h>

Expand Down
6 changes: 3 additions & 3 deletions backends/aoti/slim/core/targets.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def define_common_targets():
runtime.cxx_library(
name = "storage",
headers = [
"Storage.h",
"storage.h",
],
visibility = ["@EXECUTORCH_CLIENTS"],
exported_deps = [
Expand All @@ -25,8 +25,8 @@ def define_common_targets():
runtime.cxx_library(
name = "slimtensor",
headers = [
"SlimTensor.h",
"SlimTensorView-incl.h",
"slim_tensor.h",
"slim_tensor_view_incl.h",
],
visibility = ["@EXECUTORCH_CLIENTS"],
exported_deps = [
Expand Down
6 changes: 3 additions & 3 deletions backends/aoti/slim/core/test/test_as_strided.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

#include <gtest/gtest.h>

#include <executorch/backends/aoti/slim/core/SlimTensor.h>
#include <executorch/backends/aoti/slim/core/SlimTensorView-incl.h>
#include <executorch/backends/aoti/slim/factory/Empty.h>
#include <executorch/backends/aoti/slim/core/slim_tensor.h>
#include <executorch/backends/aoti/slim/core/slim_tensor_view_incl.h>
#include <executorch/backends/aoti/slim/factory/empty.h>

#ifdef CUDA_AVAILABLE
#include <cuda_runtime.h>
Expand Down
6 changes: 3 additions & 3 deletions backends/aoti/slim/core/test/test_permute_reshape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

#include <gtest/gtest.h>

#include <executorch/backends/aoti/slim/core/SlimTensor.h>
#include <executorch/backends/aoti/slim/core/SlimTensorView-incl.h>
#include <executorch/backends/aoti/slim/factory/Empty.h>
#include <executorch/backends/aoti/slim/core/slim_tensor.h>
#include <executorch/backends/aoti/slim/core/slim_tensor_view_incl.h>
#include <executorch/backends/aoti/slim/factory/empty.h>

#ifdef CUDA_AVAILABLE
#include <cuda_runtime.h>
Expand Down
4 changes: 2 additions & 2 deletions backends/aoti/slim/core/test/test_slimtensor_basic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

#include <gtest/gtest.h>

#include <executorch/backends/aoti/slim/core/SlimTensor.h>
#include <executorch/backends/aoti/slim/core/Storage.h>
#include <executorch/backends/aoti/slim/core/slim_tensor.h>
#include <executorch/backends/aoti/slim/core/storage.h>

namespace executorch::backends::aoti::slim {

Expand Down
6 changes: 3 additions & 3 deletions backends/aoti/slim/core/test/test_slimtensor_copy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

#include <gtest/gtest.h>

#include <executorch/backends/aoti/slim/core/SlimTensor.h>
#include <executorch/backends/aoti/slim/core/Storage.h>
#include <executorch/backends/aoti/slim/factory/Empty.h>
#include <executorch/backends/aoti/slim/core/slim_tensor.h>
#include <executorch/backends/aoti/slim/core/storage.h>
#include <executorch/backends/aoti/slim/factory/empty.h>

namespace executorch::backends::aoti::slim {

Expand Down
2 changes: 1 addition & 1 deletion backends/aoti/slim/core/test/test_slimtensor_dtypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <cstring>
#include <type_traits>

#include <executorch/backends/aoti/slim/factory/Empty.h>
#include <executorch/backends/aoti/slim/factory/empty.h>

namespace executorch::backends::aoti::slim {

Expand Down
2 changes: 1 addition & 1 deletion backends/aoti/slim/core/test/test_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include <gtest/gtest.h>

#include <executorch/backends/aoti/slim/core/Storage.h>
#include <executorch/backends/aoti/slim/core/storage.h>

#ifdef CUDA_AVAILABLE
#include <cuda_runtime.h>
Expand Down
82 changes: 82 additions & 0 deletions backends/aoti/slim/cuda/guard.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/

#pragma once

#ifdef CUDA_AVAILABLE

#include <cuda.h>
#include <cuda_runtime.h>

#include <executorch/backends/aoti/slim/c10/core/Device.h>
#include <executorch/backends/aoti/slim/c10/cuda/Exception.h>

namespace executorch::backends::aoti::slim::cuda {

/**
* CUDAGuard - RAII class that sets the current CUDA device.
*
* This class saves the current CUDA device on construction and restores it
* on destruction, providing exception-safe device switching.
*
* Thread Safety: NOT THREAD-SAFE
* - Must only be used within a single thread
*/
struct CUDAGuard {
/// No default constructor - device must be specified.
CUDAGuard() = delete;

/// Sets the current CUDA device to the specified device index.
/// @param device_index The CUDA device index to switch to.
explicit CUDAGuard(c10::DeviceIndex device_index) {
set_index(device_index);
}

/// Sets the current CUDA device to the specified device.
/// @param device The CUDA device to switch to. Must be a CUDA device.
explicit CUDAGuard(c10::Device device) {
ET_CHECK_MSG(device.is_cuda(), "Expected a CUDA device for CUDAGuard");
set_index(device.index());
}

// Copy is not allowed
CUDAGuard(const CUDAGuard&) = delete;
CUDAGuard& operator=(const CUDAGuard&) = delete;

// Move is not allowed
CUDAGuard(CUDAGuard&& other) = delete;
CUDAGuard& operator=(CUDAGuard&& other) = delete;

/// Restores the original CUDA device on destruction.
~CUDAGuard() {
if (original_device_index_ != current_device_index_) {
ET_CUDA_LOG_WARN(cudaSetDevice(original_device_index_));
}
}

/// Sets the CUDA device to the given device index.
/// @param device_index The device index to switch to.
void set_index(c10::DeviceIndex device_index) {
int orig_index = -1;
ET_CUDA_CHECK(cudaGetDevice(&orig_index));

original_device_index_ = orig_index;
current_device_index_ = device_index;
if (current_device_index_ != original_device_index_) {
ET_CUDA_CHECK(cudaSetDevice(current_device_index_));
}
}

private:
c10::DeviceIndex original_device_index_;
c10::DeviceIndex current_device_index_;
};

} // namespace executorch::backends::aoti::slim::cuda

#endif // CUDA_AVAILABLE
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

#include <cstdint>

#include <executorch/backends/aoti/slim/core/SlimTensor.h>
#include <executorch/backends/aoti/slim/util/ArrayRefUtil.h>
#include <executorch/backends/aoti/slim/util/SizeUtil.h>
#include <executorch/backends/aoti/slim/core/slim_tensor.h>
#include <executorch/backends/aoti/slim/util/array_ref_util.h>
#include <executorch/backends/aoti/slim/util/size_util.h>

namespace executorch::backends::aoti::slim {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

#pragma once

#include <executorch/backends/aoti/slim/core/SlimTensor.h>
#include <executorch/backends/aoti/slim/util/ArrayRefUtil.h>
#include <executorch/backends/aoti/slim/util/SizeUtil.h>
#include <executorch/backends/aoti/slim/core/slim_tensor.h>
#include <executorch/backends/aoti/slim/util/array_ref_util.h>
#include <executorch/backends/aoti/slim/util/size_util.h>

namespace executorch::backends::aoti::slim {

Expand Down
4 changes: 2 additions & 2 deletions backends/aoti/slim/factory/targets.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def define_common_targets():
runtime.cxx_library(
name = "empty",
headers = [
"Empty.h",
"empty.h",
],
visibility = ["@EXECUTORCH_CLIENTS"],
exported_deps = [
Expand All @@ -20,7 +20,7 @@ def define_common_targets():
runtime.cxx_library(
name = "from_blob",
headers = [
"FromBlob.h",
"from_blob.h",
],
visibility = ["@EXECUTORCH_CLIENTS"],
exported_deps = [
Expand Down
2 changes: 1 addition & 1 deletion backends/aoti/slim/factory/test/test_empty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include <gtest/gtest.h>

#include <executorch/backends/aoti/slim/factory/Empty.h>
#include <executorch/backends/aoti/slim/factory/empty.h>

#ifdef CUDA_AVAILABLE
#include <cuda_runtime.h>
Expand Down
6 changes: 3 additions & 3 deletions backends/aoti/slim/factory/test/test_from_blob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

#include <gtest/gtest.h>

#include <executorch/backends/aoti/slim/core/Storage.h>
#include <executorch/backends/aoti/slim/factory/Empty.h>
#include <executorch/backends/aoti/slim/factory/FromBlob.h>
#include <executorch/backends/aoti/slim/core/storage.h>
#include <executorch/backends/aoti/slim/factory/empty.h>
#include <executorch/backends/aoti/slim/factory/from_blob.h>

#ifdef CUDA_AVAILABLE
#include <cuda_runtime.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <optional>
#include <vector>

#include <executorch/backends/aoti/slim/util/ArrayRefUtil.h>
#include <executorch/backends/aoti/slim/util/array_ref_util.h>
#include <executorch/runtime/platform/assert.h>

namespace executorch::backends::aoti::slim {
Expand Down
6 changes: 3 additions & 3 deletions backends/aoti/slim/util/targets.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def define_common_targets():
runtime.cxx_library(
name = "shared_ptr",
headers = [
"SharedPtr.h",
"shared_ptr.h",
],
visibility = ["@EXECUTORCH_CLIENTS"],
exported_deps = [
Expand All @@ -19,7 +19,7 @@ def define_common_targets():
runtime.cxx_library(
name = "array_ref_util",
headers = [
"ArrayRefUtil.h",
"array_ref_util.h",
],
visibility = ["@EXECUTORCH_CLIENTS"],
exported_deps = [
Expand All @@ -31,7 +31,7 @@ def define_common_targets():
runtime.cxx_library(
name = "size_util",
headers = [
"SizeUtil.h",
"size_util.h",
],
visibility = ["@EXECUTORCH_CLIENTS"],
exported_deps = [
Expand Down
2 changes: 1 addition & 1 deletion backends/aoti/slim/util/test/test_size_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include <gtest/gtest.h>

#include <executorch/backends/aoti/slim/util/SizeUtil.h>
#include <executorch/backends/aoti/slim/util/size_util.h>

namespace executorch::backends::aoti::slim {

Expand Down
2 changes: 1 addition & 1 deletion backends/aoti/tests/test_common_shims_slim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <executorch/backends/aoti/common_shims_slim.h>
#include <executorch/backends/aoti/slim/c10/core/Device.h>
#include <executorch/backends/aoti/slim/c10/core/ScalarType.h>
#include <executorch/backends/aoti/slim/factory/Empty.h>
#include <executorch/backends/aoti/slim/factory/empty.h>
#include <executorch/runtime/core/error.h>
#include <executorch/runtime/platform/platform.h>

Expand Down
6 changes: 3 additions & 3 deletions backends/cuda/runtime/shims/memory_slim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

#include <executorch/backends/cuda/runtime/shims/memory_slim.h>

#include <executorch/backends/aoti/slim/factory/Empty.h>
#include <executorch/backends/aoti/slim/factory/FromBlob.h>
#include <executorch/backends/aoti/slim/util/ArrayRefUtil.h>
#include <executorch/backends/aoti/slim/factory/empty.h>
#include <executorch/backends/aoti/slim/factory/from_blob.h>
#include <executorch/backends/aoti/slim/util/array_ref_util.h>
#include <executorch/runtime/platform/assert.h>

namespace executorch::backends::cuda {
Expand Down
4 changes: 2 additions & 2 deletions backends/cuda/runtime/shims/memory_slim.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
#include <cstdint>

#include <executorch/backends/aoti/export.h>
#include <executorch/backends/aoti/slim/core/SlimTensor.h>
#include <executorch/backends/aoti/slim/core/SlimTensorView-incl.h>
#include <executorch/backends/aoti/slim/core/slim_tensor.h>
#include <executorch/backends/aoti/slim/core/slim_tensor_view_incl.h>
#include <executorch/runtime/core/error.h>

namespace executorch::backends::cuda {
Expand Down
Loading