diff --git a/CMakeLists.txt b/CMakeLists.txt index d708a6b..c2a8fb7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -108,14 +108,16 @@ IF ( (${CMAKE_C_COMPILER_ID} STREQUAL "GNU" OR ${CMAKE_C_COMPILER_ID} STREQUAL " SET (USE_CUDA ON) INCLUDE_DIRECTORIES(${CUDA_INCLUDE_DIRS}) LINK_DIRECTORIES(${CUDA_TOOLKIT_ROOT_DIR}/lib64) + LINK_DIRECTORIES(${CUDA_TOOLKIT_ROOT_DIR}/lib64/stubs) MESSAGE (STATUS "cuda include: ${CUDA_INCLUDE_DIRS}") MESSAGE (STATUS "cuda libs: ${CUDA_TOOLKIT_ROOT_DIR}/lib64") MESSAGE (STATUS "cuda version: ${CUDA_VERSION}") + SET(CUDA_PROPAGATE_HOST_FLAGS OFF) SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -lcudart -lcufft -lcublas -lnvToolsExt -DDKS_CUDA") SET (CUDA_NVCC_FLAGS "-arch=sm_35 -DDEBUG -lcufft -lcublas -lcudart -fmad=false") - + SET (CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -DDEBUG -std=c++11 -D__wsu") SET (CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} ${OPENCL_KERNELS}") #if cuda version >= 7.0 add runtime commpilation flags @@ -140,6 +142,7 @@ IF ( (${CMAKE_C_COMPILER_ID} STREQUAL "GNU" OR ${CMAKE_C_COMPILER_ID} STREQUAL " MESSAGE(STATUS "OpenCL version : ${OpenCL_VERSION_STRING}") MESSAGE(STATUS "OpenCL include dir: ${OpenCL_INCLUDE_DIR}") MESSAGE(STATUS "OpenCL library dir: ${OpenCL_LIBRARY}") + SET(CMAKE_SKIP_RPATH TRUE) INCLUDE_DIRECTORIES(${OpenCL_INCLUDE_DIR}) LINK_DIRECTORIES(${OpenCL_LIBRARY}) ENDIF (OpenCL_FOUND) diff --git a/cmake/DKSConfig.cmake.in b/cmake/DKSConfig.cmake.in index d764963..9499d8e 100644 --- a/cmake/DKSConfig.cmake.in +++ b/cmake/DKSConfig.cmake.in @@ -1,4 +1,5 @@ -SET(${PROJECT_NAME}_CMAKE_CXX_FLAGS "${${PROJECT_NAME}_CXX_FLAGS}") +SET(${PROJECT_NAME}_CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") SET(${PROJECT_NAME}_INCLUDE_DIR "${CMAKE_INSTALL_PREFIX}/include") SET(${PROJECT_NAME}_LIBRARY_DIR "${CMAKE_INSTALL_PREFIX}/lib") -SET(${PROJECT_NAME}_LIBRARY "dks") \ No newline at end of file +SET(${PROJECT_NAME}_LIBRARY "dks") +SET(CMAKE_SKIP_RPATH ${CMAKE_SKIP_RPATH}) \ No newline at end of file diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 47b1b69..64d0192 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -83,4 +83,4 @@ TARGET_LINK_LIBRARIES(testFFTSolverMIC dks ${Boost_LIBRARIES} ${CLFFT_LIBRARIES} #IF (NOT CUDA_VERSION VERSION_LESS "7.0") #ADD_EXECUTABLE(testChiSquareRT testChiSquareRT.cpp) #TARGET_LINK_LIBRARIES(testChiSquareRT dks) -#ENDIF (NOT CUDA_VERSION VERSION_LESS "7.0") \ No newline at end of file +#ENDIF (NOT CUDA_VERSION VERSION_LESS "7.0") diff --git a/test/testRandom.cpp b/test/testRandom.cpp new file mode 100644 index 0000000..64ea0df --- /dev/null +++ b/test/testRandom.cpp @@ -0,0 +1,81 @@ +#include +#include +#include +#include + +#include "DKSBase.h" + +using namespace std; + +int main(int argc, char *argv[]) { + + int size = 10; + bool apiSet = false; + char *api_name = new char[10]; + char *device_name = new char[10]; + + for (int i = 1; i < argc; i++) { + + if (argv[i] == string("-cuda")) { + strcpy(api_name, "Cuda"); + strcpy(device_name, "-gpu"); + apiSet = true; + } + + if (argv[i] == string("-opencl")) { + strcpy(api_name, "OpenCL"); + strcpy(device_name, "-gpu"); + apiSet = true; + } + + if (argv[i] == string("-N")) { + size = atoi(argv[i+1]); + i++; + } + + } + + if (!apiSet) { + strcpy(api_name, "Cuda"); + strcpy(device_name, "-gpu"); + } + + cout << "=========================BEGIN TEST=========================" << endl; + cout << "Use api: " << api_name << "\t" << device_name << endl; + cout << "Number of randoms: " << size << endl; + + //init dks + int ierr; + DKSBase base; + base.setAPI(api_name, strlen(api_name)); + base.setDevice(device_name, strlen(api_name)); + base.initDevice(); + base.callInitRandoms(size); + + //create host vector to store results + double *host_data = new double[size]; + + //create device vector + void *device_data = base.allocateMemory(size, ierr); + + for (int i = 0; i < 5; i++) { + //fill device vector with random values + base.callCreateRandomNumbers(device_data, size); + + //read device vector + base.readData(device_data, host_data, size); + + //print host data + for (int i = 0; i < size; i++) + cout << host_data[i] << " "; + cout << endl; + } + + //free device vector + base.freeMemory(device_data, size); + + //free host data + delete[] host_data; + + return 0; +}