Skip to content

Commit

Permalink
Revert D22076711: [Reland #3] Include AT_PARALLEL_OPENMP/AT_PARALLEL_…
Browse files Browse the repository at this point in the history
…NATIVE/AT_PARALLEL_NATIVE_TBB to ATen/Config.h

Test Plan: revert-hammer

Differential Revision:
D22076711

Original commit changeset: fa7b6335ebb5

fbshipit-source-id: 254b6941482f855e81c666e786fc5a4a1b57864f
  • Loading branch information
pbelevich authored and facebook-github-bot committed Jun 17, 2020
1 parent a2ef54c commit e34e328
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 53 deletions.
15 changes: 1 addition & 14 deletions .jenkins/pytorch/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -173,22 +173,9 @@ test_aten() {
}

test_torchvision() {
# pytorch extensions require including torch/extension.h which includes all.h
# which includes utils.h which includes Parallel.h.
# So you can call for instance parallel_for() from your extension,
# but the compilation will fail because of Parallel.h has only declarations
# and definitions are conditionally included Parallel.h(see last lines of Parallel.h).
# I tried to solve it #39612 and #39881 by including Config.h into Parallel.h
# But if Pytorch is built with TBB it provides Config.h
# that has AT_PARALLEL_NATIVE_TBB=1(see #3961 or #39881) and it means that if you include
# torch/extension.h which transitively includes Parallel.h
# which transitively includes tbb.h which is not available!
if [[ "${BUILD_ENVIRONMENT}" == *tbb* ]]; then
BUILD_EXT_OPTS="--global-option=build_ext --global-option=-I$PWD/third_party/tbb/include"
fi
# Check out torch/vision at Jun 11 2020 commit
# This hash must match one in .jenkins/caffe2/test.sh
pip_install $BUILD_EXT_OPTS --user git+https://github.com/pytorch/vision.git@c2e8a00885e68ae1200eb6440f540e181d9125de
pip_install --user git+https://github.com/pytorch/vision.git@c2e8a00885e68ae1200eb6440f540e181d9125de
}

test_libtorch() {
Expand Down
4 changes: 1 addition & 3 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ COMMON_COPTS = [
"-DTH_HAVE_THREAD",
"-DUSE_FBGEMM",
"-DUSE_DISTRIBUTED",
"-DAT_PARALLEL_NATIVE=1",
"-DATEN_THREADING=NATIVE",
"-DNO_CUDNN_DESTROY_HANDLE",
] + if_cuda([
Expand Down Expand Up @@ -544,9 +545,6 @@ template_rule(
"@AT_NNPACK_ENABLED@": "0",
"@CAFFE2_STATIC_LINK_CUDA_INT@": "0",
"@USE_BLAS@": "1",
"@AT_PARALLEL_OPENMP@": "0",
"@AT_PARALLEL_NATIVE@": "1",
"@AT_PARALLEL_NATIVE_TBB@": "0",
},
)

Expand Down
3 changes: 0 additions & 3 deletions aten/src/ATen/Config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,3 @@
#define AT_NNPACK_ENABLED() @AT_NNPACK_ENABLED@
#define CAFFE2_STATIC_LINK_CUDA() @CAFFE2_STATIC_LINK_CUDA_INT@
#define AT_BUILD_WITH_BLAS() @USE_BLAS@
#define AT_PARALLEL_OPENMP @AT_PARALLEL_OPENMP@
#define AT_PARALLEL_NATIVE @AT_PARALLEL_NATIVE@
#define AT_PARALLEL_NATIVE_TBB @AT_PARALLEL_NATIVE_TBB@
1 change: 0 additions & 1 deletion aten/src/ATen/Parallel.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#pragma once
#include <ATen/ATen.h>
#include <ATen/Config.h>
#include <ATen/core/ivalue.h>
#include <c10/macros/Macros.h>

Expand Down
1 change: 0 additions & 1 deletion aten/src/ATen/ParallelNative.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include <ATen/Config.h>
#if AT_PARALLEL_NATIVE
#include <ATen/Parallel.h>
#include <ATen/PTThreadPool.h>
Expand Down
1 change: 0 additions & 1 deletion aten/src/ATen/ParallelNativeTBB.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include <ATen/Config.h>
#if AT_PARALLEL_NATIVE_TBB
#include <ATen/Parallel.h>
#include <ATen/PTThreadPool.h>
Expand Down
1 change: 0 additions & 1 deletion aten/src/ATen/ParallelOpenMP.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include <ATen/Config.h>
#if AT_PARALLEL_OPENMP
#include <ATen/Parallel.h>

Expand Down
1 change: 0 additions & 1 deletion aten/src/ATen/ParallelThreadPoolNative.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include <ATen/Config.h>
#if AT_PARALLEL_OPENMP || AT_PARALLEL_NATIVE || AT_PARALLEL_NATIVE_TBB
#include <ATen/Parallel.h>
#include <ATen/PTThreadPool.h>
Expand Down
52 changes: 24 additions & 28 deletions caffe2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,6 @@ if(USE_VULKAN)
include(../cmake/VulkanCodegen.cmake)
endif()

# ATen parallelism settings
# OMP - OpenMP for intra-op, native thread pool for inter-op parallelism
# NATIVE - using native thread pool for intra- and inter-op parallelism
# TBB - using TBB for intra- and native thread pool for inter-op parallelism
if(INTERN_BUILD_MOBILE AND NOT BUILD_CAFFE2_MOBILE)
set(ATEN_THREADING "NATIVE" CACHE STRING "ATen parallel backend")
else()
set(ATEN_THREADING "OMP" CACHE STRING "ATen parallel backend")
endif()

set(AT_PARALLEL_OPENMP 0)
set(AT_PARALLEL_NATIVE 0)
set(AT_PARALLEL_NATIVE_TBB 0)

message(STATUS "Using ATen parallel backend: ${ATEN_THREADING}")
if("${ATEN_THREADING}" STREQUAL "OMP")
set(AT_PARALLEL_OPENMP 1)
elseif("${ATEN_THREADING}" STREQUAL "NATIVE")
set(AT_PARALLEL_NATIVE 1)
elseif("${ATEN_THREADING}" STREQUAL "TBB")
if(NOT USE_TBB)
message(FATAL_ERROR "Using TBB backend but USE_TBB is off")
endif()
set(AT_PARALLEL_NATIVE_TBB 1)
else()
message(FATAL_ERROR "Unknown ATen parallel backend: ${ATEN_THREADING}")
endif()

# ---[ Declare source file lists

# ---[ ATen build
Expand Down Expand Up @@ -923,6 +895,30 @@ elseif(USE_ROCM)
target_compile_definitions(torch_hip PRIVATE "-DTORCH_HIP_BUILD_MAIN_LIB")
endif()


# ATen parallelism settings
# OMP - OpenMP for intra-op, native thread pool for inter-op parallelism
# NATIVE - using native thread pool for intra- and inter-op parallelism
# TBB - using TBB for intra- and native thread pool for inter-op parallelism
if(INTERN_BUILD_MOBILE AND NOT BUILD_CAFFE2_MOBILE)
set(ATEN_THREADING "NATIVE" CACHE STRING "ATen parallel backend")
else()
set(ATEN_THREADING "OMP" CACHE STRING "ATen parallel backend")
endif()

message(STATUS "Using ATen parallel backend: ${ATEN_THREADING}")
if("${ATEN_THREADING}" STREQUAL "OMP")
target_compile_definitions(torch_cpu PUBLIC "-DAT_PARALLEL_OPENMP=1")
elseif("${ATEN_THREADING}" STREQUAL "NATIVE")
target_compile_definitions(torch_cpu PUBLIC "-DAT_PARALLEL_NATIVE=1")
elseif("${ATEN_THREADING}" STREQUAL "TBB")
if(NOT USE_TBB)
message(FATAL_ERROR "Using TBB backend but USE_TBB is off")
endif()
target_compile_definitions(torch_cpu PUBLIC "-DAT_PARALLEL_NATIVE_TBB=1")
else()
message(FATAL_ERROR "Unknown ATen parallel backend: ${ATEN_THREADING}")
endif()
set(EXPERIMENTAL_SINGLE_THREAD_POOL "0" CACHE STRING
"Experimental option to use a single thread pool for inter- and intra-op parallelism")
if("${EXPERIMENTAL_SINGLE_THREAD_POOL}")
Expand Down

0 comments on commit e34e328

Please sign in to comment.