Skip to content

Commit 2e2d049

Browse files
committed
Merge remote-tracking branch 'upstream/master' into ifu
2 parents b58da7e + 0f419ab commit 2e2d049

Some content is hidden

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

63 files changed

+2942
-1406
lines changed

CMakeLists.txt

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -404,24 +404,16 @@ else()
404404
endif()
405405

406406
# ---[ Modules
407-
# TODO(orionr): Enable all of this for Windows DLL when we
408-
# can figure out how to get it to build
409-
if (NOT (MSVC AND BUILD_SHARED_LIBS))
410407
add_subdirectory(modules)
411-
endif()
412408

413409
# ---[ Binaries
414410
# Binaries will be built after the Caffe2 main libraries and the modules
415411
# are built. For the binaries, they will be linked to the Caffe2 main
416412
# libraries, as well as all the modules that are built with Caffe2 (the ones
417413
# built in the previous Modules section above).
418-
# TODO(orionr): Enable all of this for Windows DLL when we
419-
# can figure out how to get it to build
420-
if (NOT (MSVC AND BUILD_SHARED_LIBS))
421414
if (BUILD_BINARY)
422415
add_subdirectory(binaries)
423416
endif()
424-
endif()
425417

426418
include(cmake/Summary.cmake)
427419
caffe2_print_configuration_summary()

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) || defined(CAFFE2_BUILD_MAIN_LIB)
4+
# if defined(ATen_cuda_EXPORTS) || defined(caffe2_gpu_EXPORTS) || defined(CAFFE2_CUDA_BUILD_MAIN_LIB)
55
# define AT_CUDA_API __declspec(dllexport)
66
# else
77
# define AT_CUDA_API __declspec(dllimport)

aten/src/THC/THCGeneral.h.in

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

2424
#ifdef _WIN32
25-
# if defined(ATen_cuda_EXPORTS) || defined(caffe2_gpu_EXPORTS) || defined(CAFFE2_BUILD_MAIN_LIB)
25+
# if defined(ATen_cuda_EXPORTS) || defined(caffe2_gpu_EXPORTS) || defined(CAFFE2_CUDA_BUILD_MAIN_LIB)
2626
# define THC_API THC_EXTERNC __declspec(dllexport)
2727
# define THC_CLASS __declspec(dllexport)
2828
# else

caffe2/CMakeLists.txt

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,6 @@ endif()
6565
# ---[ Caffe2 build
6666
# Note: the folders that are being commented out have not been properly
6767
# addressed yet.
68-
# TODO(orionr): Enable all of this for Windows DLL when we
69-
# can figure out how to get it to build
70-
if (MSVC AND BUILD_SHARED_LIBS)
71-
add_subdirectory(utils)
72-
else()
7368
add_subdirectory(proto)
7469
add_subdirectory(contrib)
7570
add_subdirectory(core)
@@ -101,7 +96,6 @@ add_subdirectory(sgd)
10196
add_subdirectory(share)
10297
# add_subdirectory(test) # todo: use caffe2_gtest_main instead of gtest_main because we will need to call GlobalInit
10398
add_subdirectory(transforms)
104-
endif()
10599

106100
# Advanced: if we have white list specified, we will do intersections for all
107101
# main lib srcs.
@@ -166,16 +160,8 @@ if (FALSE)
166160
endif()
167161

168162
# ---[ List of libraries to link with
169-
# TODO(orionr): Enable all of this for Windows DLL when we
170-
# can figure out how to get it to build
171-
if (NOT (MSVC AND BUILD_SHARED_LIBS))
172163
add_library(caffe2_protos STATIC $<TARGET_OBJECTS:Caffe2_PROTO>)
173164
add_dependencies(caffe2_protos Caffe2_PROTO)
174-
else()
175-
# Do not include caffe2 or caffe protos, but rather have it only be
176-
# a library to attach local protobuf.
177-
add_library(caffe2_protos STATIC utils/dummy.cpp)
178-
endif()
179165
# If we are going to link protobuf locally inside caffe2 libraries, what we will do is
180166
# to create a helper static library that always contains libprotobuf source files, and
181167
# link the caffe2 related dependent libraries to it.
@@ -341,7 +327,7 @@ if(USE_CUDA)
341327
# NB: This must be target_compile_definitions, not target_compile_options,
342328
# as the latter is not respected by nvcc
343329
if (MSVC)
344-
target_compile_definitions(caffe2_gpu PRIVATE "-DCAFFE2_BUILD_MAIN_LIB")
330+
target_compile_definitions(caffe2_gpu PRIVATE "-DCAFFE2_CUDA_BUILD_MAIN_LIB")
345331
endif()
346332

347333
# Set standard properties on the target
@@ -401,9 +387,6 @@ if ($ENV{WERROR})
401387
endif()
402388

403389
# ---[ Test binaries.
404-
# TODO(orionr): Enable all of this for Windows DLL when we
405-
# can figure out how to get it to build
406-
if (NOT (MSVC AND BUILD_SHARED_LIBS))
407390
if (BUILD_TEST)
408391
set(Caffe2_ALL_TEST_SRCS ${Caffe2_CPU_TEST_SRCS})
409392
if (USE_CUDA)
@@ -414,6 +397,8 @@ if (BUILD_TEST)
414397
get_filename_component(test_name ${test_src} NAME_WE)
415398
add_executable(${test_name} "${test_src}")
416399
target_link_libraries(${test_name} ${Caffe2_MAIN_LIBS} gtest_main)
400+
target_include_directories(${test_name} PRIVATE $<INSTALL_INTERFACE:include>)
401+
target_include_directories(${test_name} PRIVATE ${Caffe2_CPU_INCLUDE})
417402
if (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 3.0)
418403
target_compile_features(${test_name} PRIVATE cxx_range_for)
419404
endif()
@@ -429,6 +414,8 @@ if (BUILD_TEST)
429414
get_filename_component(test_name ${test_src} NAME_WE)
430415
hip_add_executable(${test_name} "${test_src}")
431416
target_link_libraries(${test_name} ${Caffe2_MAIN_LIBS} gtest_main)
417+
target_include_directories(${test_name} PRIVATE $<INSTALL_INTERFACE:include>)
418+
target_include_directories(${test_name} PRIVATE ${Caffe2_CPU_INCLUDE})
432419
if (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 3.0)
433420
target_compile_features(${test_name} PRIVATE cxx_range_for)
434421
endif()
@@ -439,13 +426,13 @@ if (BUILD_TEST)
439426
endforeach()
440427
endif()
441428
endif()
442-
endif()
443429

444430
set(__aten_test_dir "test/aten")
445431
if (NOT USE_ROCM)
446432
foreach(test_src ${ATen_CPU_TEST_SRCS})
447433
get_filename_component(test_name ${test_src} NAME_WE)
448434
add_executable(${test_name} "${test_src}")
435+
target_include_directories(${test_name} PRIVATE $<INSTALL_INTERFACE:include>)
449436
target_include_directories(${test_name} PRIVATE ${Caffe2_CPU_INCLUDE})
450437
target_include_directories(${test_name} SYSTEM PRIVATE ${Caffe2_DEPENDENCY_INCLUDE})
451438
target_link_libraries(${test_name} ${Caffe2_MAIN_LIBS})
@@ -457,6 +444,7 @@ if (NOT USE_ROCM)
457444
foreach(test_src ${ATen_CUDA_TEST_SRCS})
458445
get_filename_component(test_name ${test_src} NAME_WE)
459446
torch_cuda_based_add_executable(${test_name} "${test_src}")
447+
target_include_directories(${test_name} PRIVATE $<INSTALL_INTERFACE:include>)
460448
target_include_directories(${test_name} PRIVATE ${Caffe2_CPU_INCLUDE})
461449
target_include_directories(${test_name} SYSTEM PRIVATE ${Caffe2_DEPENDENCY_INCLUDE})
462450
target_link_libraries(${test_name} ${Caffe2_MAIN_LIBS})
@@ -466,9 +454,6 @@ if (NOT USE_ROCM)
466454
endif()
467455
endif()
468456

469-
# TODO(orionr): Enable all of this for Windows DLL when we
470-
# can figure out how to get it to build
471-
if (NOT (MSVC AND BUILD_SHARED_LIBS))
472457
if (BUILD_PYTHON)
473458
# Python site-packages
474459
# Get canonical directory for python site packages (relative to install
@@ -525,6 +510,9 @@ if (BUILD_PYTHON)
525510
if (APPLE)
526511
set_target_properties(caffe2_pybind11_state PROPERTIES LINK_FLAGS "-undefined dynamic_lookup")
527512
endif()
513+
target_include_directories(caffe2_pybind11_state PRIVATE $<INSTALL_INTERFACE:include>)
514+
target_include_directories(caffe2_pybind11_state PRIVATE ${Caffe2_CPU_INCLUDE})
515+
528516
target_link_libraries(
529517
caffe2_pybind11_state caffe2_library)
530518
if (WIN32)
@@ -547,6 +535,8 @@ if (BUILD_PYTHON)
547535
if (APPLE)
548536
set_target_properties(caffe2_pybind11_state_gpu PROPERTIES LINK_FLAGS "-undefined dynamic_lookup")
549537
endif()
538+
target_include_directories(caffe2_pybind11_state_gpu PRIVATE $<INSTALL_INTERFACE:include>)
539+
target_include_directories(caffe2_pybind11_state_gpu PRIVATE ${Caffe2_CPU_INCLUDE})
550540
target_link_libraries(
551541
caffe2_pybind11_state_gpu caffe2_library caffe2_gpu_library)
552542
if (WIN32)
@@ -570,6 +560,8 @@ if (BUILD_PYTHON)
570560
if (APPLE)
571561
set_target_properties(caffe2_pybind11_state_hip PROPERTIES LINK_FLAGS "-undefined dynamic_lookup")
572562
endif()
563+
target_include_directories(caffe2_pybind11_state_hip PRIVATE $<INSTALL_INTERFACE:include>)
564+
target_include_directories(caffe2_pybind11_state_hip PRIVATE ${Caffe2_CPU_INCLUDE})
573565
target_link_libraries(
574566
caffe2_pybind11_state_hip caffe2_library caffe2_hip_library)
575567
if (WIN32)
@@ -657,7 +649,6 @@ if (BUILD_PYTHON)
657649
install(DIRECTORY ${CMAKE_BINARY_DIR}/caffe2 DESTINATION ${PYTHON_LIB_REL_PATH}
658650
FILES_MATCHING PATTERN "*.py")
659651
endif()
660-
endif()
661652

662653
# Finally, set the Caffe2_MAIN_LIBS variable in the parent scope.
663654
set(Caffe2_MAIN_LIBS ${Caffe2_MAIN_LIBS} PARENT_SCOPE)

caffe2/core/common_gpu.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,42 @@
2525
#include "caffe2/core/logging.h"
2626
#include "caffe2/core/common.h"
2727

28+
// Defines CAFFE2_CUDA_EXPORT and CAFFE2_CUDA_IMPORT. On Windows, this corresponds to
29+
// different declarations (dllexport and dllimport). On Linux/Mac, it just
30+
// resolves to the same "default visibility" setting.
31+
#if defined(_MSC_VER)
32+
#if defined(CAFFE2_BUILD_SHARED_LIBS)
33+
#define CAFFE2_CUDA_EXPORT __declspec(dllexport)
34+
#define CAFFE2_CUDA_IMPORT __declspec(dllimport)
35+
#else
36+
#define CAFFE2_CUDA_EXPORT
37+
#define CAFFE2_CUDA_IMPORT
38+
#endif
39+
#else
40+
#if defined(__GNUC__)
41+
#define CAFFE2_CUDA_EXPORT __attribute__((__visibility__("default")))
42+
#else
43+
#define CAFFE2_CUDA_EXPORT
44+
#endif
45+
#define CAFFE2_CUDA_IMPORT CAFFE2_CUDA_EXPORT
46+
#endif
47+
48+
// CAFFE2_CUDA_API is a macro that, depends on whether you are building the
49+
// main caffe2 library or not, resolves to either CAFFE2_CUDA_EXPORT or
50+
// CAFFE2_CUDA_IMPORT.
51+
//
52+
// This is used in e.g. Caffe2's protobuf files: when building the main library,
53+
// it is defined as CAFFE2_CUDA_EXPORT to fix a Windows global-variable-in-dll
54+
// issue, and for anyone dependent on Caffe2 it will be defined as
55+
// CAFFE2_CUDA_IMPORT.
56+
57+
#ifdef CAFFE2_CUDA_BUILD_MAIN_LIB
58+
#define CAFFE2_CUDA_API CAFFE2_CUDA_EXPORT
59+
#else
60+
#define CAFFE2_CUDA_API CAFFE2_CUDA_IMPORT
61+
#endif
62+
63+
2864
// This is a macro defined for cuda fp16 support. In default, cuda fp16 is
2965
// supported by NVCC 7.5, but it is also included in the Tegra X1 platform with
3066
// a (custom?) NVCC 7.0. As a result, we would normally just check the cuda

caffe2/core/context_gpu.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ enum class CudaMemoryPoolType {
3333
*
3434
* The memory pool is set up during caffe2's global initialization time.
3535
*/
36-
CAFFE2_API CudaMemoryPoolType GetCudaMemoryPoolType();
36+
CAFFE2_CUDA_API CudaMemoryPoolType GetCudaMemoryPoolType();
3737

3838
/**
3939
* A struct to host thread-local cuda objects.
@@ -44,7 +44,7 @@ CAFFE2_API CudaMemoryPoolType GetCudaMemoryPoolType();
4444
* and deallocating these objects at the thread scope. This class is solely
4545
* used inside CUDAContext and should not be used externally.
4646
*/
47-
class CAFFE2_API ThreadLocalCUDAObjects {
47+
class CAFFE2_CUDA_API ThreadLocalCUDAObjects {
4848
friend class CUDAContext;
4949

5050
private:
@@ -135,9 +135,9 @@ class CAFFE2_API ThreadLocalCUDAObjects {
135135
#endif // CAFFE2_USE_CUDNN
136136
};
137137

138-
CAFFE2_API BaseStaticContext* GetCUDAStaticContext();
138+
CAFFE2_CUDA_API BaseStaticContext* GetCUDAStaticContext();
139139

140-
class CAFFE2_API CUDAContext final : public BaseContext {
140+
class CAFFE2_CUDA_API CUDAContext final : public BaseContext {
141141
public:
142142
// The default cuda context constructor.
143143
explicit CUDAContext(const int gpu_id = -1);
@@ -332,7 +332,7 @@ inline void CPUContext::CopyBytes<CPUContext, CUDAContext>(
332332
* GPU present during runtime, at global initialization time we will set
333333
* the CPU memory allocator to allocate pinned memory.
334334
*/
335-
struct CAFFE2_API PinnedCPUAllocator final : CPUAllocator {
335+
struct CAFFE2_CUDA_API PinnedCPUAllocator final : CPUAllocator {
336336
PinnedCPUAllocator() {}
337337
~PinnedCPUAllocator() override {}
338338
std::pair<void*, MemoryDeleter> New(size_t nbytes) override {
@@ -381,7 +381,7 @@ struct CAFFE2_API PinnedCPUAllocator final : CPUAllocator {
381381
DefaultCPUAllocator baseAllocator_;
382382
};
383383

384-
class CAFFE2_API CUDAStaticContext final : public BaseStaticContext {
384+
class CAFFE2_CUDA_API CUDAStaticContext final : public BaseStaticContext {
385385
public:
386386
std::pair<void*, MemoryDeleter> New(size_t nbytes) const override;
387387

caffe2/core/nomnigraph/CMakeLists.txt

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,15 @@ file(GLOB_RECURSE NOMNI_SRCS *.cc)
33
file(GLOB_RECURSE NOMNI_TEST_SRCS *Test.cc)
44
exclude(NOMNI_SRCS "${NOMNI_SRCS}" "${NOMNI_TEST_SRCS}")
55

6-
# TODO(orionr): The nomnigraph source should likely just be included
7-
# in the Caffe2 source list, since this won't live separately
8-
add_library(nomnigraph STATIC "${NOMNI_SRCS}")
9-
target_compile_options(nomnigraph PRIVATE "-DCAFFE2_BUILD_MAIN_LIB")
10-
add_dependencies(nomnigraph Caffe2_PROTO)
6+
list(APPEND Caffe2_CPU_SRCS ${NOMNI_SRCS})
7+
list(APPEND Caffe2_CPU_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/include)
8+
list(APPEND Caffe2_CPU_TEST_SRCS ${NOMNI_TEST_SRCS})
119

12-
target_include_directories(nomnigraph PUBLIC
13-
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
14-
$<INSTALL_INTERFACE:include>)
15-
list(APPEND Caffe2_PUBLIC_DEPENDENCY_LIBS nomnigraph)
16-
set(Caffe2_PUBLIC_DEPENDENCY_LIBS ${Caffe2_PUBLIC_DEPENDENCY_LIBS} PARENT_SCOPE)
17-
18-
install(TARGETS nomnigraph EXPORT Caffe2Targets DESTINATION lib)
19-
install(DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/include
10+
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include
2011
DESTINATION include
2112
FILES_MATCHING PATTERN "*.h")
2213

23-
if (BUILD_TEST)
24-
foreach(test_src ${NOMNI_TEST_SRCS})
25-
get_filename_component(test_name ${test_src} NAME_WE)
26-
add_executable(${test_name} "${test_src}")
27-
target_link_libraries(${test_name} nomnigraph gtest_main)
28-
add_test(NAME ${test_name} COMMAND $<TARGET_FILE:${test_name}>)
29-
install(TARGETS ${test_name} DESTINATION test)
30-
endforeach()
31-
endif()
14+
# ---[ Send the lists to the parent scope.
15+
set(Caffe2_CPU_SRCS ${Caffe2_CPU_SRCS} PARENT_SCOPE)
16+
set(Caffe2_CPU_INCLUDE ${Caffe2_CPU_INCLUDE} PARENT_SCOPE)
17+
set(Caffe2_CPU_TEST_SRCS ${Caffe2_CPU_TEST_SRCS} PARENT_SCOPE)

0 commit comments

Comments
 (0)