Skip to content

GPU and CPU compilation possible #117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: topic-alpaka
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ image: coin/archlinux

script:
- date
- export ROOT_PATH=$(pwd)
- git clone https://github.com/ComputationalRadiationPhysics/alpaka.git --depth=1 --branch develop --single-branch alpaka
- mkdir build_tmp && cd build_tmp
- cmake -DCUDA_TOOLKIT_ROOT_DIR=/opt/cuda -DCMAKE_CXX_FLAGS="-Werror" ..
- cmake -Dalpaka_DIR=$ROOT_PATH/alpaka -DCUDA_TOOLKIT_ROOT_DIR=/opt/cuda -DCMAKE_CXX_FLAGS="-Werror" ..
- make
- ls -l
17 changes: 9 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ endif(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8.2)
################################################################################
# Find alpaka
################################################################################
SET(ALPAKA_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/include/alpaka/" CACHE STRING "The location of the alpaka library")
LIST(APPEND CMAKE_MODULE_PATH "${ALPAKA_ROOT}")
#SET(ALPAKA_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/include/alpaka/" CACHE STRING "The location of the alpaka library")
#LIST(APPEND CMAKE_MODULE_PATH "${ALPAKA_ROOT}")

find_package("alpaka" REQUIRED)
include_directories(SYSTEM ${alpaka_INCLUDE_DIRS})
add_definitions(${alpaka_DEFINITIONS})
add_definitions(${alpaka_DEFINITIONS})
add_definitions(${ALPAKA_DEV_COMPILE_OPTIONS})
set(LIBS ${LIBS} ${alpaka_LIBRARIES})

################################################################################
Expand Down Expand Up @@ -80,7 +81,7 @@ set(LIBS ${LIBS} ${CMAKE_THREAD_LIBS_INIT})
################################################################################
# GNU
if(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
Expand Down Expand Up @@ -169,22 +170,22 @@ endif(MSVC)
# Executables
###############################################################################
set(HASEonGPU_NAME "calcPhiASE")
file(GLOB SRCFILES "${CMAKE_CURRENT_SOURCE_DIR}/src/*.c*")
file(GLOB SRCFILES "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp")

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)

if(NOT MPI_FOUND)
LIST(REMOVE_ITEM SRCFILES ${CMAKE_CURRENT_SOURCE_DIR}/src/calc_phi_ase_mpi.cc)
LIST(REMOVE_ITEM SRCFILES ${CMAKE_CURRENT_SOURCE_DIR}/src/calc_phi_ase_mpi.cpp)
endif()

if(Boost_MPI_FOUND)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/graybat)
else()
LIST(REMOVE_ITEM SRCFILES ${CMAKE_CURRENT_SOURCE_DIR}/src/calc_phi_ase_graybat.cc)
LIST(REMOVE_ITEM SRCFILES ${CMAKE_CURRENT_SOURCE_DIR}/src/calc_phi_ase_graybat.cpp)
endif()


add_executable(${HASEonGPU_NAME} ${SRCFILES})
alpaka_add_executable(${HASEonGPU_NAME} ${SRCFILES})
target_link_libraries(${HASEonGPU_NAME} ${LIBS})


Expand Down
6 changes: 3 additions & 3 deletions include/RandomGenerator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ struct RandomGenerator {
std::declval<uint32_t &>()));
using Dist = decltype(alpaka::rand::distribution::createUniformReal<float>(std::declval<T_Acc const &>()));

RandomGenerator(T_Acc const &acc, unsigned const seed, unsigned const subsequence) : gen(alpaka::rand::generator::createDefault(acc, seed, subsequence)),
dist(alpaka::rand::distribution::createUniformReal<float>(acc)) {
ALPAKA_FN_HOST_ACC RandomGenerator(T_Acc const &acc, unsigned const seed, unsigned const subsequence) : gen(alpaka::rand::generator::createDefault(acc, seed, subsequence)),
dist(alpaka::rand::distribution::createUniformReal<float>(acc)) {

}

double operator()(){
ALPAKA_FN_HOST_ACC double operator()(){
return dist(gen);
}

Expand Down
4 changes: 2 additions & 2 deletions include/calc_sample_gain_sum.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ struct CalcSampleGainSumWithReflection {
double gainSumSquareTemp = 0;
Point samplePoint = mesh.getSamplePoint(sample_i);

auto * blockOffset(alpaka::block::shared::allocArr<unsigned, 4>(acc)); // 4 in case of warp-based raynumber
auto * blockOffset(alpaka::block::shared::st::allocArr<unsigned, 4, 0>(acc)); // 4 in case of warp-based raynumber
blockOffset[0] = 0;

const unsigned nElementsPerThread = 128;
Expand Down Expand Up @@ -260,7 +260,7 @@ struct CalcSampleGainSum {
double gainSumSquareTemp = 0;
Point samplePoint = mesh.getSamplePoint(sample_i);

auto * blockOffset(alpaka::block::shared::allocArr<unsigned, 4>(acc)); // 4 in case of warp-based raynumber
auto * blockOffset(alpaka::block::shared::st::allocArr<unsigned, 4, 0>(acc)); // 4 in case of warp-based raynumber
blockOffset[0] = 0;

const unsigned nElementsPerThread = 128;
Expand Down
7 changes: 5 additions & 2 deletions include/importance_sampling.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,14 @@ unsigned importanceSamplingDistribution(T_Stream &stream,
const float sumPhi,
const bool distributeRandomly){

using Size = std::size_t;
using Dim = alpaka::dim::DimInt<1>;
using Host = alpaka::acc::AccCpuSerial<Dim, Size>;
using DevAcc = alpaka::dev::Dev<T_Stream>;
using DevHost = alpaka::dev::DevCpu;
using DevHost = alpaka::dev::Dev<Host>;

DevAcc devAcc (alpaka::dev::getDev(stream));
DevHost devHost (alpaka::dev::cpu::getDev());
DevHost devHost (alpaka::dev::DevMan<Host>::getDevByIdx(0));

auto hSumPhi ( alpaka::mem::buf::alloc<float, std::size_t, std::size_t, DevHost>(devHost, static_cast<std::size_t>(1)));
auto hRaysDump ( alpaka::mem::buf::alloc<unsigned, std::size_t, std::size_t, DevHost>(devHost, static_cast<std::size_t>(1)));
Expand Down
Loading