Skip to content

Commit 81bf33d

Browse files
authored
Merge pull request pytorch#140 from iotamudelta/master
Merge from upstream
2 parents f6c3a99 + 44f3d9f commit 81bf33d

File tree

74 files changed

+1301
-338
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+1301
-338
lines changed

.jenkins/caffe2/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ if [[ $BUILD_ENVIRONMENT == *rocm* ]]; then
157157
export HCC_AMDGPU_TARGET=gfx900
158158
159159
########## HIPIFY Caffe2 operators
160+
${PYTHON} "${ROOT_DIR}/tools/amd_build/build_pytorch_amd.py"
160161
${PYTHON} "${ROOT_DIR}/tools/amd_build/build_caffe2_amd.py"
161162
fi
162163
@@ -190,7 +191,6 @@ else
190191
fi
191192
192193
193-
194194
###############################################################################
195195
# Configure and make
196196
###############################################################################

.jenkins/pytorch/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ cmake --version
3030
pip install -r requirements.txt || true
3131

3232
if [[ "$BUILD_ENVIRONMENT" == *rocm* ]]; then
33-
export MAX_JOBS=4
3433
# This is necessary in order to cross compile (or else we'll have missing GPU device).
3534
export HCC_AMDGPU_TARGET=gfx900
3635

@@ -48,6 +47,7 @@ if [[ "$BUILD_ENVIRONMENT" == *rocm* ]]; then
4847
sudo apt-get install libc++abi1
4948

5049
python tools/amd_build/build_pytorch_amd.py
50+
python tools/amd_build/build_caffe2_amd.py
5151
USE_ROCM=1 python setup.py install --user
5252
exit 0
5353
fi

CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ endif()
5555
include(CMakeDependentOption)
5656
option(BUILD_TORCH "Build Torch" OFF)
5757
option(BUILD_CAFFE2 "Build Caffe2" ON)
58-
option(BUILD_ATEN "Build ATen" OFF)
58+
option(ATEN_NO_TEST "Do not build ATen test binaries" OFF)
59+
option(BUILD_ATEN_MOBILE "Build ATen for Android and iOS" OFF)
5960
option(BUILD_BINARY "Build C++ binaries" ON)
6061
option(BUILD_DOCS "Build Caffe2 documentation" OFF)
6162
option(BUILD_CUSTOM_PROTOBUF "Build and use Caffe2's own protobuf under third_party" ON)
@@ -75,7 +76,6 @@ cmake_dependent_option(
7576
"BUILD_TEST" OFF)
7677
option(USE_ACL "Use ARM Compute Library" OFF)
7778
option(USE_ASAN "Use Address Sanitizer" OFF)
78-
option(USE_ATEN "Use ATen" OFF)
7979
option(USE_CUDA "Use CUDA" ON)
8080
option(USE_ROCM "Use ROCm" OFF)
8181
option(CAFFE2_STATIC_LINK_CUDA "Statically link CUDA libraries" OFF)
@@ -145,8 +145,8 @@ option(USE_DISTRIBUTED_MW "Use THD (distributed) master worker" OFF)
145145
# Used when building Caffe2 through setup.py
146146
option(BUILDING_WITH_TORCH_LIBS "Tell cmake if Caffe2 is being built alongside torch libs" OFF)
147147

148-
if (USE_ATEN)
149-
set(BUILD_ATEN ${USE_ATEN})
148+
if (ANDROID OR IOS)
149+
set(BUILD_ATEN_MOBILE ON)
150150
endif()
151151

152152
# ---[ CMake scripts + modules

aten/CMakeLists.txt

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
if (CAFFE2_CMAKE_BUILDING_WITH_MAIN_REPO)
2-
if (NOT BUILD_ATEN)
3-
return()
4-
endif()
5-
else()
1+
if (NOT CAFFE2_CMAKE_BUILDING_WITH_MAIN_REPO)
62
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
73
project(ATen CXX C)
84
include(CMakeDependentOption)
@@ -14,9 +10,10 @@ else()
1410
USE_CUDNN "Use cuDNN" ON
1511
"USE_CUDA" OFF)
1612
option(ATEN_NO_TEST "Do not build ATen test binaries" OFF)
17-
18-
# Flag for shared dependencies
19-
set(BUILD_ATEN ON)
13+
else()
14+
if (BUILD_ATEN_MOBILE)
15+
return()
16+
endif()
2017
endif()
2118

2219
# Find modules

aten/src/ATen/ATenGeneral.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
#include "ATen/core/Macros.h"
44

55
// TODO: Merge the *_API macros.
6-
#define AT_API AT_CORE_API
6+
#define AT_API AT_CORE_API

aten/src/ATen/CMakeLists.txt

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,6 @@ IF(NOT MSVC)
1313
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-absolute-value")
1414
ENDIF(NOT MSVC)
1515

16-
################################################################################
17-
# Helper functions
18-
################################################################################
19-
20-
function(filter_list output input)
21-
unset(result)
22-
foreach(filename ${${input}})
23-
foreach(pattern ${ARGN})
24-
if("${filename}" MATCHES "${pattern}")
25-
list(APPEND result "${filename}")
26-
endif()
27-
endforeach()
28-
endforeach()
29-
set(${output} ${result} PARENT_SCOPE)
30-
endfunction()
31-
32-
3316
# Can be compiled standalone
3417
IF(NOT AT_INSTALL_BIN_DIR OR NOT AT_INSTALL_LIB_DIR OR NOT AT_INSTALL_INCLUDE_DIR OR NOT AT_INSTALL_SHARE_DIR)
3518
SET(AT_INSTALL_BIN_DIR "bin" CACHE PATH "AT install binary subdirectory")

aten/src/ATen/cuda/ATenCUDAGeneral.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#pragma once
22

33
#ifdef _WIN32
4-
# if defined(ATen_cuda_EXPORTS) || defined(caffe2_gpu_EXPORTS)
4+
# if defined(ATen_cuda_EXPORTS) || defined(caffe2_gpu_EXPORTS) || defined(CAFFE2_BUILD_MAIN_LIB)
55
# define AT_CUDA_API __declspec(dllexport)
66
# else
77
# define AT_CUDA_API __declspec(dllimport)

aten/src/ATen/native/Convolution.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ auto ConvParams::use_miopen(const at::Tensor& input) const -> bool {
127127

128128
auto ConvParams::use_mkldnn(const at::Tensor& input) const -> bool {
129129
#if AT_MKLDNN_ENABLED()
130-
return input.type().backend() == kCPU &&
130+
return input.type().backend() == at::Backend::CPU &&
131131
input.type().scalarType() == kFloat && // only on CPU Float Tensors
132132
!is_dilated() && // doesn't support dilation
133133
!transposed && // or transposed tensors

aten/src/ATen/native/cuda/SpectralOps.cu

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,16 @@ using namespace at::native::detail;
2929
// counting_iterator => index to fill
3030
struct cnt_to_dst_idx_functor : public thrust::unary_function<int64_t, int64_t>
3131
{
32-
const int64_t last_dim_size;
33-
const int64_t last_dim_start_slice;
34-
const int64_t last_dim_to_fill_size;
32+
int64_t last_dim_size;
33+
int64_t last_dim_start_slice;
34+
int64_t last_dim_to_fill_size;
3535

3636
cnt_to_dst_idx_functor(int64_t last_dim_size, int64_t last_dim_start_slice) :
3737
last_dim_size(last_dim_size), last_dim_start_slice(last_dim_start_slice),
3838
last_dim_to_fill_size(last_dim_size - last_dim_start_slice) {}
39+
40+
__host__ __device__
41+
cnt_to_dst_idx_functor & operator=(const cnt_to_dst_idx_functor&) = default;
3942

4043
__host__ __device__ __forceinline__
4144
int64_t operator()(const int64_t& i) const

aten/src/THC/THCBlas.cu

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ void THCudaBlas_Dgetrf(THCState *state, int n, double **a, int lda, int *pivot,
514514
THCublasCheck(cublasDgetrfBatched(handle, n, a, lda, pivot, info, batchSize));
515515
}
516516

517-
THC_API void THCudaBlas_Sgetrs(THCState *state, char transa, int n, int nrhs, const float **a, int lda, int *pivot, float **b, int ldb, int *info, int batchSize)
517+
void THCudaBlas_Sgetrs(THCState *state, char transa, int n, int nrhs, const float **a, int lda, int *pivot, float **b, int ldb, int *info, int batchSize)
518518
{
519519
if( (n >= INT_MAX) || (nrhs >= INT_MAX) || (lda >= INT_MAX) || (ldb >= INT_MAX) || (batchSize >= INT_MAX) )
520520
{
@@ -531,7 +531,7 @@ THC_API void THCudaBlas_Sgetrs(THCState *state, char transa, int n, int nrhs, co
531531
}
532532

533533

534-
THC_API void THCudaBlas_Dgetrs(THCState *state, char transa, int n, int nrhs, const double **a, int lda, int *pivot, double **b, int ldb, int *info, int batchSize)
534+
void THCudaBlas_Dgetrs(THCState *state, char transa, int n, int nrhs, const double **a, int lda, int *pivot, double **b, int ldb, int *info, int batchSize)
535535
{
536536
if( (n >= INT_MAX) || (nrhs >= INT_MAX) || (lda >= INT_MAX) || (ldb >= INT_MAX) || (batchSize >= INT_MAX) )
537537
{

aten/src/THC/THCGeneral.h.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#endif
2424

2525
#ifdef _WIN32
26-
# if defined(ATen_cuda_EXPORTS) || defined(caffe2_gpu_EXPORTS)
26+
# if defined(ATen_cuda_EXPORTS) || defined(caffe2_gpu_EXPORTS) || defined(CAFFE2_BUILD_MAIN_LIB)
2727
# define THC_API THC_EXTERNC __declspec(dllexport)
2828
# define THC_CLASS __declspec(dllexport)
2929
# else

aten/src/THC/THCSleep.cu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ __global__ void spin_kernel(int64_t cycles)
1212
}
1313
}
1414

15-
THC_API void THC_sleep(THCState* state, int64_t cycles)
15+
void THC_sleep(THCState* state, int64_t cycles)
1616
{
1717
dim3 grid(1);
1818
dim3 block(1);

caffe2/CMakeLists.txt

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ include(../cmake/Codegen.cmake)
77
add_subdirectory(utils)
88

99
# ---[ ATen build
10-
if(BUILD_ATEN)
10+
if (NOT BUILD_ATEN_MOBILE)
1111
set(__caffe2_CMAKE_POSITION_INDEPENDENT_CODE ${CMAKE_POSITION_INDEPENDENT_CODE})
1212
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
1313
set(AT_LINK_STYLE INTERFACE)
@@ -49,7 +49,7 @@ if(BUILD_ATEN)
4949

5050
IF(USE_ROCM)
5151
# Set the HIP Variables
52-
set(Caffe2_HIP_SRCS ${ATen_CUDA_SRCS})
52+
set(Caffe2_HIP_SRCS ${Caffe2_HIP_SRCS} ${ATen_CUDA_SRCS})
5353
set(Caffe2_HIP_INCLUDES ${Caffe2_HIP_INCLUDES} ${Caffe2_GPU_INCLUDE})
5454
ENDIF(USE_ROCM)
5555
else()
@@ -340,6 +340,12 @@ if(USE_CUDA)
340340
target_compile_options(caffe2_gpu PUBLIC "-DAT_CORE_STATIC_WINDOWS=1")
341341
endif()
342342

343+
# NB: This must be target_compile_definitions, not target_compile_options,
344+
# as the latter is not respected by nvcc
345+
if (MSVC)
346+
target_compile_definitions(caffe2_gpu PRIVATE "-DCAFFE2_BUILD_MAIN_LIB")
347+
endif()
348+
343349
# Set standard properties on the target
344350
aten_set_target_props(caffe2_gpu)
345351

@@ -351,21 +357,19 @@ endif()
351357
# ---[ Caffe2 HIP sources.
352358
if(USE_ROCM)
353359
# Call again since Caffe2_HIP_INCLUDES is extended with ATen include dirs.
354-
if(BUILD_ATEN)
355-
# Get Compile Definitions from the directory (FindHIP.cmake bug)
356-
get_directory_property(MY_DEFINITIONS COMPILE_DEFINITIONS)
357-
if(MY_DEFINITIONS)
358-
foreach(_item ${MY_DEFINITIONS})
359-
LIST(APPEND HIP_HCC_FLAGS "-D${_item}")
360-
endforeach()
361-
endif()
362-
363-
# Call again since Caffe2_HIP_INCLUDES is extended with ATen include dirs.
364-
hip_include_directories(${Caffe2_HIP_INCLUDES})
360+
# Get Compile Definitions from the directory (FindHIP.CMake bug)
361+
get_directory_property(MY_DEFINITIONS COMPILE_DEFINITIONS)
362+
if(MY_DEFINITIONS)
363+
foreach(_item ${MY_DEFINITIONS})
364+
LIST(APPEND HIP_HCC_FLAGS "-D${_item}")
365+
endforeach()
365366
endif()
366-
IF(BUILD_CAFFE2)
367-
set_source_files_properties(${Caffe2_HIP_SRCS} PROPERTIES HIP_SOURCE_PROPERTY_FORMAT 1)
368-
ENDIF()
367+
368+
# Call again since Caffe2_HIP_INCLUDES is extended with ATen include dirs.
369+
hip_include_directories(${Caffe2_HIP_INCLUDES})
370+
371+
filter_list(__caffe2_hip_srcs_cpp Caffe2_HIP_SRCS "\\.(cc|cpp|cu)$")
372+
set_source_files_properties(${__caffe2_hip_srcs_cpp} PROPERTIES HIP_SOURCE_PROPERTY_FORMAT 1)
369373

370374
# FindHIP.CMake checks if the SHARED flag is set and adds extra logic accordingly.
371375
hip_add_library(caffe2_hip ${Caffe2_HIP_SRCS})
@@ -444,7 +448,7 @@ if(BUILD_CAFFE2)
444448
set(__aten_test_dir "test/aten")
445449
endif()
446450
# Todo - Set up ATen tests for ROCm in an upcoming PR
447-
if(BUILD_ATEN AND NOT USE_ROCM)
451+
if(NOT USE_ROCM)
448452
foreach(test_src ${ATen_CPU_TEST_SRCS})
449453
get_filename_component(test_name ${test_src} NAME_WE)
450454
add_executable(${test_name} "${test_src}")

caffe2/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Caffe2 is a lightweight, modular, and scalable deep learning framework. Building
66

77
## Questions and Feedback
88

9-
Please use Github issues (https://github.com/caffe2/caffe2/issues) to ask questions, report bugs, and request new features.
9+
Please use Github issues (https://github.com/pytorch/pytorch/issues) to ask questions, report bugs, and request new features.
1010

1111
### Further Resources on [Caffe2.ai](http://caffe2.ai)
1212

caffe2/contrib/aten/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
if(BUILD_ATEN)
1+
if(NOT BUILD_ATEN_MOBILE)
22
# Add source generated by Codegen.cmake and pass to parent
33
list(APPEND Caffe2_CPU_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/aten_op.cc)
44
list(APPEND Caffe2_GPU_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/aten_op_cuda.cc)

caffe2/core/common.h

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -94,19 +94,6 @@ using std::vector;
9494
#define CAFFE2_NORETURN __attribute__((noreturn))
9595
#endif
9696

97-
/**
98-
* Macro for marking functions as having public visibility.
99-
* Ported from folly/CPortability.h
100-
*/
101-
#ifndef __GNUC_PREREQ
102-
#if defined __GNUC__ && defined __GNUC_MINOR__
103-
#define __GNUC_PREREQ(maj, min) \
104-
((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
105-
#else
106-
#define __GNUC_PREREQ(maj, min) 0
107-
#endif
108-
#endif
109-
11097
// Defines CAFFE2_EXPORT and CAFFE2_IMPORT. On Windows, this corresponds to
11198
// different declarations (dllexport and dllimport). On Linux/Mac, it just
11299
// resolves to the same "default visibility" setting.
@@ -120,11 +107,7 @@ using std::vector;
120107
#endif
121108
#else
122109
#if defined(__GNUC__)
123-
#if __GNUC_PREREQ(4, 9)
124-
#define CAFFE2_EXPORT [[gnu::visibility("default")]]
125-
#else
126110
#define CAFFE2_EXPORT __attribute__((__visibility__("default")))
127-
#endif
128111
#else
129112
#define CAFFE2_EXPORT
130113
#endif

caffe2/core/graph.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace transform {
1616
/**
1717
* Graph representation of an operator.
1818
*/
19-
struct Node {
19+
struct CAFFE2_API Node {
2020
public:
2121
// Empty constructor for resize
2222
Node() {}
@@ -45,7 +45,7 @@ struct Node {
4545
/**
4646
* Graph representation of a Netdef.
4747
*/
48-
struct Graph {
48+
struct CAFFE2_API Graph {
4949
public:
5050
/**
5151
* Given a subgraph, gets all of the parents of the subgraph, as well as
@@ -155,7 +155,7 @@ struct Graph {
155155

156156
// Adds an operator def to a netdef.
157157
// Returns the ptr, if you want to add anything extra (such as device_option)
158-
OperatorDef* AddOp(
158+
CAFFE2_API OperatorDef* AddOp(
159159
NetDef* netdef_ptr,
160160
string op_type,
161161
std::vector<string> inputs,
@@ -168,12 +168,12 @@ OperatorDef* AddOp(
168168
* For example, if we wanted to match an operator to Conv or FC, we can give:
169169
* "Conv|FC" as the type() of that op.
170170
*/
171-
bool MatchStrings(string p, string s);
171+
CAFFE2_API bool MatchStrings(string p, string s);
172172

173173
/**
174174
* This ensures that each named arg that exists in the pattern exists in g_op,
175175
* is equal in value.
176176
*/
177-
bool MatchArguments(const OperatorDef& p_op, const OperatorDef& g_op);
177+
CAFFE2_API bool MatchArguments(const OperatorDef& p_op, const OperatorDef& g_op);
178178

179179
} // namespace caffe2

caffe2/core/net_simple.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace caffe2 {
1616
// This is the very basic structure you need to run a network - all it
1717
// does is simply to run everything in sequence. If you want more fancy control
1818
// such as a DAG-like execution, check out other better net implementations.
19-
class SimpleNet : public NetBase {
19+
class CAFFE2_API SimpleNet : public NetBase {
2020
public:
2121
SimpleNet(const std::shared_ptr<const NetDef>& net_def, Workspace* ws);
2222
bool SupportsAsync() override {

caffe2/core/nomnigraph/Representations/NeuralNet.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,12 +199,13 @@ NNNodeMatchCriteria matchAnyNode() {
199199
[](NNGraph::NodeRef /* unused */) { return true; }, "matchAnyNode");
200200
}
201201

202-
NNMatchGraph::NodeRef operatorTree(
202+
NNMatchGraph::NodeRef operatorSubgraph(
203203
NNMatchGraph& g,
204204
const NNNodeMatchCriteria& root,
205205
const std::vector<NNMatchGraph::NodeRef>& childrenCriteria,
206206
int count) {
207-
return tree(g, matchAnyNode(), {tree(g, root, childrenCriteria)}, count);
207+
return subgraph(
208+
g, matchAnyNode(), {subgraph(g, root, childrenCriteria)}, count);
208209
}
209210

210211
} // namespace nn

caffe2/core/nomnigraph/include/nomnigraph/Graph/Graph.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,10 @@ class Graph {
412412
return result;
413413
}
414414

415+
size_t getEdgesCount() const {
416+
return (size_t)edges_.size();
417+
}
418+
415419
private:
416420
std::list<Node<T, U...>> nodes_;
417421
std::list<Edge<T, U...>> edges_;

0 commit comments

Comments
 (0)