Skip to content

Commit dcd0aae

Browse files
committed
[ExecuTorch] Proof-of-concept: use c10/macros in ExecuTorch
Step 0 for code sharing: can we use c10 Macros? This needs a guardrail to prevent breaking the ExecuTorch core requirements before we can ship it. What's our current guard against accidentally including streams/heap allocation/etc. in core at runtime? Differential Revision: [D65241695](https://our.internmc.facebook.com/intern/diff/D65241695/) [ghstack-poisoned]
1 parent 09cf982 commit dcd0aae

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,9 @@ endif()
507507
target_include_directories(
508508
executorch_core PUBLIC ${_common_include_directories}
509509
)
510+
target_include_directories(
511+
executorch_core INTERFACE ${TORCH_INCLUDE_DIRS}
512+
)
510513
target_compile_options(executorch_core PUBLIC ${_common_compile_options})
511514
if(MAX_KERNEL_NUM)
512515
target_compile_definitions(
@@ -668,6 +671,8 @@ if(EXECUTORCH_BUILD_PTHREADPOOL
668671
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/threadpool)
669672
endif()
670673

674+
find_package(Torch CONFIG REQUIRED)
675+
671676
if(EXECUTORCH_BUILD_PYBIND)
672677
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/third-party/pybind11)
673678

@@ -680,7 +685,6 @@ if(EXECUTORCH_BUILD_PYBIND)
680685
endif()
681686

682687
# find pytorch lib, to allow pybind to take at::Tensor as input/output
683-
find_package(Torch CONFIG REQUIRED)
684688
find_library(
685689
TORCH_PYTHON_LIBRARY torch_python PATHS "${TORCH_INSTALL_PREFIX}/lib"
686690
)

runtime/platform/compiler.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
#pragma once
1515

16+
#include <c10/macros/Macros.h>
17+
1618
/*
1719
* Compiler support checks. Follows the logic used by pytorch/c10/util/C++17.h
1820
* but may support older versions.
@@ -55,9 +57,9 @@
5557
*/
5658

5759
#define ET_NORETURN [[noreturn]]
58-
#define ET_NOINLINE __attribute__((noinline))
59-
#define ET_INLINE __attribute__((always_inline)) inline
60-
#define ET_INLINE_ATTRIBUTE __attribute__((always_inline))
60+
#define ET_NOINLINE C10_NOINLINE
61+
#define ET_INLINE C10_ALWAYS_INLINE
62+
#define ET_INLINE_ATTRIBUTE C10_ALWAYS_INLINE_ATTRIBUTE
6163

6264
#if defined(__GNUC__)
6365

@@ -88,14 +90,14 @@
8890
// do something
8991
// }
9092
#if (__cplusplus) >= 202002L
91-
93+
// TODO: backport these to c10 and remove ET definition
9294
#define ET_LIKELY(expr) (expr) [[likely]]
9395
#define ET_UNLIKELY(expr) (expr) [[unlikely]]
9496

9597
#else
9698

97-
#define ET_LIKELY(expr) (expr)
98-
#define ET_UNLIKELY(expr) (expr)
99+
#define ET_LIKELY(expr) C10_LIKELY(expr)
100+
#define ET_UNLIKELY(expr) C10_UNLIKELY(expr)
99101

100102
#endif // (__cplusplus) >= 202002L
101103

runtime/platform/targets.bzl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ def define_common_targets():
122122
exported_headers = [
123123
"compiler.h",
124124
],
125+
exported_deps = [
126+
"//caffe2/c10:c10",
127+
] if not runtime.is_oss else [],
125128
visibility = [
126129
"//executorch/...",
127130
"@EXECUTORCH_CLIENTS",

0 commit comments

Comments
 (0)