commit
f9c21f56b7
@ -1,10 +0,0 @@
|
|||||||
CCFLAGS = -std=c++11 -I/work/paddle
|
|
||||||
CC = nvcc
|
|
||||||
|
|
||||||
all : place_test
|
|
||||||
|
|
||||||
place.o : place.h place.cu
|
|
||||||
$(CC) $(CCFLAGS) -c place.cu -o $@
|
|
||||||
|
|
||||||
place_test : place.o place_test.cu
|
|
||||||
$(CC) $(CCFLAGS) -lgtest -lgtest_main $^ -o $@
|
|
@ -1,61 +0,0 @@
|
|||||||
#include <majel/place.h>
|
|
||||||
|
|
||||||
namespace majel {
|
|
||||||
|
|
||||||
namespace detail {
|
|
||||||
|
|
||||||
class PlacePrinter
|
|
||||||
: public boost::static_visitor<> {
|
|
||||||
private:
|
|
||||||
std::ostream& os_;
|
|
||||||
public:
|
|
||||||
PlacePrinter(std::ostream& os) : os_(os) {}
|
|
||||||
|
|
||||||
void operator()(const CpuPlace&) {
|
|
||||||
os_ << "CpuPlace";
|
|
||||||
}
|
|
||||||
|
|
||||||
void operator()(const GpuPlace& p) {
|
|
||||||
os_ << "GpuPlace(" << p.device << ")";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace majel
|
|
||||||
|
|
||||||
static Place the_default_place;
|
|
||||||
|
|
||||||
void set_place(const Place& place) {
|
|
||||||
the_default_place = place;
|
|
||||||
}
|
|
||||||
|
|
||||||
const Place& get_place() {
|
|
||||||
return the_default_place;
|
|
||||||
}
|
|
||||||
|
|
||||||
const GpuPlace default_gpu() {
|
|
||||||
return GpuPlace(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
const CpuPlace default_cpu() {
|
|
||||||
return CpuPlace();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool is_gpu_place(const Place& p) {
|
|
||||||
return boost::apply_visitor(IsGpuPlace(), p);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool is_cpu_place(const Place& p) {
|
|
||||||
return !boost::apply_visitor(IsGpuPlace(), p);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool places_are_same_class(const Place& p1, const Place& p2) {
|
|
||||||
return is_gpu_place(p1) == is_gpu_place(p2);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::ostream& operator<<(std::ostream& os, const majel::Place& p) {
|
|
||||||
majel::detail::PlacePrinter printer(os);
|
|
||||||
boost::apply_visitor(printer, p);
|
|
||||||
return os;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace majel
|
|
@ -0,0 +1,2 @@
|
|||||||
|
build
|
||||||
|
third-party
|
@ -0,0 +1,34 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.0)
|
||||||
|
|
||||||
|
if(GTEST_INCLUDE_DIR AND GTEST_LIBRARIES)
|
||||||
|
message("-- Found gtest (include: ${GTEST_INCLUDE_DIR}, library: ${GTEST_LIBRARIES})")
|
||||||
|
else()
|
||||||
|
# find #include <majel/xx.h>
|
||||||
|
get_filename_component(PARENT_DIR ${CMAKE_CURRENT_SOURCE_DIR} DIRECTORY)
|
||||||
|
include_directories(${PARENT_DIR})
|
||||||
|
|
||||||
|
# find cmake directory modules
|
||||||
|
get_filename_component(PARENT_DIR ${PARENT_DIR} DIRECTORY)
|
||||||
|
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PARENT_DIR}/cmake")
|
||||||
|
|
||||||
|
# enable c++11
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
||||||
|
|
||||||
|
# enable gtest
|
||||||
|
set(THIRD_PARTY_PATH ${CMAKE_CURRENT_SOURCE_DIR}/third_party)
|
||||||
|
set(WITH_TESTING ON)
|
||||||
|
include(external/gtest)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
########################### Build Majel #############################
|
||||||
|
set(MAJEL_CXX_FILES place.cpp)
|
||||||
|
set(MAJEL_CUDA_FILES "")
|
||||||
|
|
||||||
|
if(CUDA_FOUND)
|
||||||
|
cuda_add_library(majel ${MAJEL_CUDA_FILES} ${MAJEL_CXX_FILES})
|
||||||
|
else()
|
||||||
|
add_library(majel ${MAJEL_CXX_FILES})
|
||||||
|
endif()
|
||||||
|
#####################################################################
|
||||||
|
|
||||||
|
add_subdirectory(test)
|
@ -0,0 +1,49 @@
|
|||||||
|
#include <majel/place.h>
|
||||||
|
|
||||||
|
namespace majel {
|
||||||
|
|
||||||
|
namespace detail {
|
||||||
|
|
||||||
|
class PlacePrinter : public boost::static_visitor<> {
|
||||||
|
private:
|
||||||
|
std::ostream& os_;
|
||||||
|
|
||||||
|
public:
|
||||||
|
PlacePrinter(std::ostream& os) : os_(os) {}
|
||||||
|
|
||||||
|
void operator()(const CpuPlace&) { os_ << "CpuPlace"; }
|
||||||
|
|
||||||
|
void operator()(const GpuPlace& p) { os_ << "GpuPlace(" << p.device << ")"; }
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace majel
|
||||||
|
|
||||||
|
static Place the_default_place;
|
||||||
|
|
||||||
|
void set_place(const Place& place) { the_default_place = place; }
|
||||||
|
|
||||||
|
const Place& get_place() { return the_default_place; }
|
||||||
|
|
||||||
|
const GpuPlace default_gpu() { return GpuPlace(0); }
|
||||||
|
|
||||||
|
const CpuPlace default_cpu() { return CpuPlace(); }
|
||||||
|
|
||||||
|
bool is_gpu_place(const Place& p) {
|
||||||
|
return boost::apply_visitor(IsGpuPlace(), p);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool is_cpu_place(const Place& p) {
|
||||||
|
return !boost::apply_visitor(IsGpuPlace(), p);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool places_are_same_class(const Place& p1, const Place& p2) {
|
||||||
|
return is_gpu_place(p1) == is_gpu_place(p2);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ostream& operator<<(std::ostream& os, const majel::Place& p) {
|
||||||
|
majel::detail::PlacePrinter printer(os);
|
||||||
|
boost::apply_visitor(printer, p);
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace majel
|
@ -0,0 +1,10 @@
|
|||||||
|
file(GLOB_RECURSE ALL_TEST_FILES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "*.cpp" "*.cc")
|
||||||
|
|
||||||
|
add_executable(majel_tests ${ALL_TEST_FILES})
|
||||||
|
add_dependencies(majel_tests majel)
|
||||||
|
target_link_libraries(majel_tests
|
||||||
|
${Boost_LIBRARIES}
|
||||||
|
${GTEST_LIBRARIES}
|
||||||
|
majel
|
||||||
|
)
|
||||||
|
add_test(majel_tests majel_tests)
|
@ -0,0 +1,6 @@
|
|||||||
|
#include "gtest/gtest.h"
|
||||||
|
|
||||||
|
int main(int argc, char** argv) {
|
||||||
|
::testing::InitGoogleTest(&argc, argv);
|
||||||
|
return RUN_ALL_TESTS();
|
||||||
|
}
|
Loading…
Reference in new issue