mirror of
https://github.com/saymrwulf/pytorch.git
synced 2026-05-14 20:57:59 +00:00
Added basic build system
This commit is contained in:
parent
dea27ca4ca
commit
e9de70f296
4 changed files with 141 additions and 0 deletions
39
CMakeLists.txt
Normal file
39
CMakeLists.txt
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
#cmake_minimum_required(VERSION 2.8.12)
|
||||
cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR)
|
||||
|
||||
project(Caffe2 CXX)
|
||||
|
||||
# TODO(bwasti): versioning
|
||||
|
||||
# Useful functions.
|
||||
function (exclude OUTPUT INPUT)
|
||||
set(EXCLUDES ${ARGN})
|
||||
foreach(EXCLUDE ${EXCLUDES})
|
||||
list(REMOVE_ITEM INPUT "${EXCLUDE}")
|
||||
endforeach()
|
||||
set(${OUTPUT} ${INPUT} PARENT_SCOPE)
|
||||
endfunction(exclude)
|
||||
|
||||
function (prepend OUTPUT PREPEND)
|
||||
set(OUT "")
|
||||
foreach(ITEM ${ARGN})
|
||||
list(APPEND OUT "${PREPEND}${ITEM}")
|
||||
endforeach()
|
||||
set(${OUTPUT} ${OUT} PARENT_SCOPE)
|
||||
endfunction(prepend)
|
||||
|
||||
# Third party builds.
|
||||
include_directories(${CMAKE_SOURCE_DIR})
|
||||
file(GLOB Caffe2_THIRD_PARTY "${CMAKE_SOURCE_DIR}/third_party/*")
|
||||
include_directories(${Caffe2_THIRD_PARTY})
|
||||
|
||||
# googletest.
|
||||
add_subdirectory("${CMAKE_SOURCE_DIR}/third_party/googletest")
|
||||
include_directories("${CMAKE_SOURCE_DIR}/third_party/googletest/googletest/include")
|
||||
|
||||
# Old caffe protobuf.
|
||||
add_subdirectory(caffe/proto)
|
||||
|
||||
add_subdirectory(caffe2)
|
||||
target_link_libraries(Caffe2_CPU)
|
||||
target_compile_features(Caffe2_CPU PRIVATE cxx_range_for)
|
||||
|
|
@ -8,3 +8,10 @@ Read [the installation instructions](https://github.com/Yangqing/caffe2/blob/mas
|
|||
|
||||
Caffe2 is released under the [BSD 2-Clause license](https://github.com/Yangqing/caffe2/blob/master/LICENSE).
|
||||
|
||||
### Building Caffe2
|
||||
|
||||
git clone https://github.com/caffe2/caffe2
|
||||
cd caffe2 && mkdir bin
|
||||
cd bin && cmake ..
|
||||
make
|
||||
|
||||
|
|
|
|||
87
caffe2/CMakeLists.txt
Normal file
87
caffe2/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
# Excludes
|
||||
set(Caffe2_DIR_EXCLUDES
|
||||
"/binaries"
|
||||
"/contrib"
|
||||
"/distributed"
|
||||
"/mpi"
|
||||
"/image"
|
||||
"/experiments"
|
||||
"/python"
|
||||
)
|
||||
set(Caffe2_FILE_EXCLUDES
|
||||
"/core/init_omp.cc"
|
||||
"/operators/fully_connected_op_sparse.cc"
|
||||
"/test/caffe2_gtest_main.cc"
|
||||
"/core/init_omp.cc"
|
||||
"/db/db_test.cc"
|
||||
"/db/leveldb.cc"
|
||||
"/db/lmdb.cc"
|
||||
"/db/rocksdb.cc"
|
||||
"/db/zmqdb.cc"
|
||||
)
|
||||
|
||||
set(Caffe2_CPU_FILE_EXCLUDES
|
||||
"/contrib/nervana/nervana_fc_op_gpu_test.cc"
|
||||
"/core/blob_gpu_test.cc"
|
||||
"/core/context_gpu_test.cc"
|
||||
"/mpi/mpi_gpu_test.cc"
|
||||
"/operators/conv_op_cache_cudnn_test.cc"
|
||||
"/operators/elementwise_op_gpu_test.cc"
|
||||
"/operators/fully_connected_op_gpu_test.cc"
|
||||
"/operators/operator_fallback_gpu_test.cc"
|
||||
"/operators/utility_ops_gpu_test.cc"
|
||||
)
|
||||
|
||||
# Expand all the exludes.
|
||||
prepend(Caffe2_DIR_EXCLUDES ${CMAKE_CURRENT_SOURCE_DIR} ${Caffe2_DIR_EXCLUDES})
|
||||
prepend(Caffe2_FILE_EXCLUDES ${CMAKE_CURRENT_SOURCE_DIR} ${Caffe2_FILE_EXCLUDES})
|
||||
prepend(Caffe2_CPU_FILE_EXCLUDES ${CMAKE_CURRENT_SOURCE_DIR} ${Caffe2_CPU_FILE_EXCLUDES})
|
||||
|
||||
# Get all source directories.
|
||||
# TODO(bwasti): GLOB is not considered best practice.
|
||||
file(GLOB Caffe2_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/*)
|
||||
|
||||
# Exclude all excluded directories.
|
||||
exclude(Caffe2_DIRS "${Caffe2_DIRS}" ${Caffe2_DIR_EXCLUDES})
|
||||
|
||||
# Get all source files from remaining directories.
|
||||
|
||||
# GPU files
|
||||
foreach(dir ${Caffe2_DIRS})
|
||||
file(GLOB tmp ${dir}/*_cudnn.cc)
|
||||
set(Caffe2_GPU_SRCS ${Caffe2_GPU_SRCS} ${tmp})
|
||||
endforeach()
|
||||
foreach(dir ${Caffe2_DIRS})
|
||||
file(GLOB tmp ${dir}/*_gpu.cc)
|
||||
set(Caffe2_GPU_SRCS ${Caffe2_GPU_SRCS} ${tmp})
|
||||
endforeach()
|
||||
exclude(Caffe2_GPU_SRCS "${Caffe2_GPU_SRCS}" ${Caffe2_FILE_EXCLUDES})
|
||||
|
||||
# CPU files.
|
||||
foreach(dir ${Caffe2_DIRS})
|
||||
file(GLOB tmp ${dir}/*.cc)
|
||||
set(Caffe2_CPU_SRCS ${Caffe2_CPU_SRCS} ${tmp})
|
||||
endforeach()
|
||||
exclude(Caffe2_CPU_SRCS "${Caffe2_CPU_SRCS}" ${Caffe2_FILE_EXCLUDES})
|
||||
exclude(Caffe2_CPU_SRCS "${Caffe2_CPU_SRCS}" ${Caffe2_CPU_FILE_EXCLUDES})
|
||||
exclude(Caffe2_CPU_SRCS "${Caffe2_CPU_SRCS}" ${Caffe2_GPU_SRCS})
|
||||
|
||||
# CPU test files.
|
||||
set(Caffe2_CPU_TEST_SRCS
|
||||
"/test/caffe2_gtest_main.cc"
|
||||
)
|
||||
prepend(Caffe2_CPU_TEST_SRCS ${CMAKE_CURRENT_SOURCE_DIR} ${Caffe2_CPU_TEST_SRCS})
|
||||
|
||||
# Compile protobufs.
|
||||
add_subdirectory(proto)
|
||||
include_directories(BEFORE ${CMAKE_BINARY_DIR})
|
||||
|
||||
# Compile exposed libraries.
|
||||
add_library(Caffe2_CPU ${Caffe2_CPU_SRCS})
|
||||
target_link_libraries(Caffe2_CPU Caffe2_PROTO)
|
||||
|
||||
# Compile test binaries.
|
||||
add_executable(Caffe2_CPU_TEST ${Caffe2_CPU_TEST_SRCS})
|
||||
|
||||
target_link_libraries(Caffe2_CPU_TEST Caffe2_CPU gtest)
|
||||
target_compile_features(Caffe2_CPU_TEST PRIVATE cxx_range_for)
|
||||
8
caffe2/proto/CMakeLists.txt
Normal file
8
caffe2/proto/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
find_package(Protobuf REQUIRED)
|
||||
|
||||
file(GLOB Caffe2_PROTOBUF_FILES "${CMAKE_CURRENT_SOURCE_DIR}/*.proto")
|
||||
|
||||
PROTOBUF_GENERATE_CPP(Caffe2_PROTO_SRCS Caffe2_PROTO_HEADERS ${Caffe2_PROTOBUF_FILES})
|
||||
|
||||
add_library(Caffe2_PROTO ${Caffe2_PROTO_HEADERS} ${Caffe2_PROTO_SRCS})
|
||||
target_include_directories(Caffe2_PROTO PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
|
||||
Loading…
Reference in a new issue