File tree Expand file tree Collapse file tree 9 files changed +58
-9
lines changed Expand file tree Collapse file tree 9 files changed +58
-9
lines changed Original file line number Diff line number Diff line change @@ -24,11 +24,15 @@ if(NOT TORCHAO_INCLUDE_DIRS)
24
24
set (TORCHAO_INCLUDE_DIRS ${TORCHAO_ROOT} /../.. )
25
25
endif ()
26
26
27
+ if (NOT TORCHAO_OP_TARGET )
28
+ message (FATAL_ERROR "TORCHAO_OP_TARGET is not set. Set it to ATEN or EXECUTORCH." )
29
+ endif ()
30
+
27
31
if (NOT TORCHAO_PARALLEL_BACKEND )
28
32
if (TORCHAO_OP_TARGET STREQUAL "ATEN" )
29
33
set (TORCHAO_PARALLEL_BACKEND "ATEN_OPENMP" )
30
34
elseif (TORCHAO_OP_TARGET STREQUAL "EXECUTORCH" )
31
- set (TORCHAO_PARALLEL_BACKEND "PTHREADPOOL " )
35
+ set (TORCHAO_PARALLEL_BACKEND "EXECUTORCH " )
32
36
else ()
33
37
message (TORCHAO_PARALLEL_BACKEND "TORCHAO_PARALLEL_BACKEND is not set. Please set it directly or set TORCHAO_OP_TARGET to get a default." )
34
38
endif ()
Original file line number Diff line number Diff line change @@ -23,6 +23,14 @@ function(target_link_torchao_parallel_backend target_name torchao_parallel_backe
23
23
target_compile_definitions (${target_name} PRIVATE TORCHAO_PARALLEL_ATEN=1 AT_PARALLEL_OPENMP=1 INTRA_OP_PARALLEL=1 )
24
24
target_link_libraries (${target_name} PRIVATE ${TORCH_INSTALL_PREFIX} /lib/libomp${CMAKE_SHARED_LIBRARY_SUFFIX} )
25
25
26
+ elseif (TORCHAO_PARALLEL_BACKEND_TOUPPER STREQUAL "EXECUTORCH" )
27
+ message (STATUS "Building with TORCHAO_PARALLEL_BACKEND=TORCHAO_PARALLEL_EXECUTORCH" )
28
+ message (STATUS "EXECUTORCH_INCLUDE_DIRS: ${EXECUTORCH_INCLUDE_DIRS} " )
29
+ message (STATUS "EXECUTORCH_LIBRARIES: ${EXECUTORCH_LIBRARIES} " )
30
+ target_include_directories (${target_name} PRIVATE "${EXECUTORCH_INCLUDE_DIRS} " )
31
+ target_link_libraries (${target_name} PRIVATE "${EXECUTORCH_LIBRARIES} " )
32
+ target_compile_definitions (${target_name} PRIVATE TORCHAO_PARALLEL_EXECUTORCH=1 )
33
+
26
34
elseif (TORCHAO_PARALLEL_BACKEND_TOUPPER STREQUAL "OPENMP" )
27
35
message (STATUS "Building with TORCHAO_PARALLEL_BACKEND=OPENMP. You must set the CMake variable OpenMP_ROOT to the OMP library location before compiling. Do not use this option if Torch was built with OPENMP; use ATEN_OPENMP instead." )
28
36
find_package (OpenMP REQUIRED )
Original file line number Diff line number Diff line change @@ -11,8 +11,8 @@ export CMAKE_OUT=/tmp/cmake-out/torchao
11
11
cmake -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH} \
12
12
-DCMAKE_INSTALL_PREFIX=${CMAKE_OUT} \
13
13
-DTORCHAO_OP_TARGET=" $1 " \
14
- -DEXECUTORCH_LIBRARIES=${EXECUTORCH_LIBRARIES} \
15
- -DEXECUTORCH_INCLUDE_DIRS=${EXECUTORCH_INCLUDE_DIRS} \
14
+ -DEXECUTORCH_LIBRARIES=" ${EXECUTORCH_LIBRARIES} " \
15
+ -DEXECUTORCH_INCLUDE_DIRS=" ${EXECUTORCH_INCLUDE_DIRS} " \
16
16
-S . \
17
17
-B ${CMAKE_OUT}
18
18
cmake --build ${CMAKE_OUT} --target install --config Release
Original file line number Diff line number Diff line change @@ -13,3 +13,8 @@ if (CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")
13
13
${TORCHAO_INCLUDE_DIRS} /torchao/experimental/kernels/cpu/aarch64/valpacking/interleave.cpp
14
14
)
15
15
endif ()
16
+
17
+ install (
18
+ TARGETS torchao_kernels_aarch64
19
+ DESTINATION lib
20
+ )
Original file line number Diff line number Diff line change @@ -10,3 +10,8 @@ include(${TORCHAO_ROOT}/Utils.cmake)
10
10
11
11
add_library (torchao_ops_linear_${TORCHAO_PARALLEL_BACKEND} STATIC channelwise_8bit_activation_groupwise_lowbit_weight.cpp )
12
12
target_link_torchao_parallel_backend (torchao_ops_linear_${TORCHAO_PARALLEL_BACKEND} "${TORCHAO_PARALLEL_BACKEND} " )
13
+
14
+ install (
15
+ TARGETS torchao_ops_linear_${TORCHAO_PARALLEL_BACKEND}
16
+ DESTINATION lib
17
+ )
Original file line number Diff line number Diff line change @@ -93,7 +93,7 @@ LinearTilingParams get_default_linear_tiling_params(
93
93
94
94
LinearTilingParams tiling_params;
95
95
auto num_threads = torchao::get_num_threads ();
96
- assert (num_threads >= 1 );
96
+ TORCHAO_CHECK (num_threads >= 1 , " num_threads must be >= 1 " );
97
97
98
98
tiling_params.mc_by_mr = 1 ;
99
99
int mc = tiling_params.mc_by_mr * ukernel_config.mr ;
Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ if(TORCHAO_OP_TARGET STREQUAL "ATEN")
19
19
target_compile_definitions (linear_a8wxdq_${TORCHAO_OP_TARGET} PRIVATE USE_ATEN=1 )
20
20
elseif (TORCHAO_OP_TARGET STREQUAL "EXECUTORCH" )
21
21
message (STATUS "Building with TORCHAO_OP_TARGET=EXECUTORCH" )
22
- add_library (linear_a8wxdq_${TORCHAO_OP_TARGET} SHARED
22
+ add_library (linear_a8wxdq_${TORCHAO_OP_TARGET} STATIC
23
23
linear_a8wxdq_executorch/w2s.cpp
24
24
linear_a8wxdq_executorch/w2sz.cpp
25
25
linear_a8wxdq_executorch/w3s.cpp
@@ -29,9 +29,9 @@ elseif(TORCHAO_OP_TARGET STREQUAL "EXECUTORCH")
29
29
linear_a8wxdq_executorch/w5s.cpp
30
30
linear_a8wxdq_executorch/w5sz.cpp
31
31
)
32
- target_include_directories (linear_a8wxdq_${TORCHAO_OP_TARGET} PRIVATE ${EXECUTORCH_INCLUDE_DIRS} )
32
+ target_include_directories (linear_a8wxdq_${TORCHAO_OP_TARGET} PRIVATE " ${EXECUTORCH_INCLUDE_DIRS} " )
33
33
target_compile_definitions (linear_a8wxdq_${TORCHAO_OP_TARGET} PRIVATE USE_EXECUTORCH=1 )
34
- target_link_libraries (linear_a8wxdq_${TORCHAO_OP_TARGET} PRIVATE ${EXECUTORCH_LIBRARIES} )
34
+ target_link_libraries (linear_a8wxdq_${TORCHAO_OP_TARGET} PRIVATE " ${EXECUTORCH_LIBRARIES} " )
35
35
target_link_libraries (linear_a8wxdq_${TORCHAO_OP_TARGET} PRIVATE torchao_kernels_aarch64 )
36
36
target_link_libraries (linear_a8wxdq_${TORCHAO_OP_TARGET} PRIVATE torchao_ops_linear_${TORCHAO_PARALLEL_BACKEND} )
37
37
else ()
Original file line number Diff line number Diff line change
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+ // All rights reserved.
3
+ //
4
+ // This source code is licensed under the license found in the
5
+ // LICENSE file in the root directory of this source tree.
6
+
7
+ #pragma once
8
+
9
+ #include < executorch/extension/threadpool/threadpool.h>
10
+
11
+ template <typename F>
12
+ void torchao::parallel_1d (const int64_t begin, const int64_t end, const F& f) {
13
+ torch::executorch::threadpool::get_threadpool ()->run (
14
+ [&](size_t i) {
15
+ int64_t idx = begin + i;
16
+ f (idx);
17
+ },
18
+ end - begin);
19
+ }
20
+
21
+ inline void torchao::set_num_threads (int num_threads) {
22
+ torch::executorch::threadpool::get_threadpool ()->_unsafe_reset_threadpool (
23
+ num_threads);
24
+ }
25
+
26
+ inline int torchao::get_num_threads () {
27
+ return torch::executorch::threadpool::get_threadpool ()->get_thread_count ();
28
+ }
Original file line number Diff line number Diff line change @@ -34,8 +34,7 @@ int get_num_threads();
34
34
#ifdef TORCHAO_PARALLEL_EXECUTORCH
35
35
#pragma message( \
36
36
" TORCHAO_PARALLEL_EXECUTORCH is set. Using ExecuTorch parallel backend." )
37
-
38
- #error "TORCHAO_PARALLEL_EXECUTORCH is not implemented yet"
37
+ #include < torchao/experimental/ops/parallel-executorch-impl.h>
39
38
40
39
#else
41
40
#ifdef TORCHAO_PARALLEL_PTHREADPOOL
You can’t perform that action at this time.
0 commit comments