Skip to content

Commit

Permalink
Update alpaka dependency (#69)
Browse files Browse the repository at this point in the history
* Remove alpaka submodule

* Delete alpaka extern folder

* Get alpaka with FetchContent

* Upgrade C++ standard to 20

* Update to latest alpaka API

* Delete unnecessary line

* Update benchmarking scripts

* Formatting

* Update alpaka API call

* Add docker image with alpaka preinstalled

* Update package version
  • Loading branch information
sbaldu authored Dec 23, 2024
1 parent 5e1749c commit 389b73a
Show file tree
Hide file tree
Showing 16 changed files with 105 additions and 33 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,3 @@
path = extern/pybind11
url = https://github.com/sbaldu/pybind11.git
branch = master
[submodule "extern/alpaka"]
path = extern/alpaka
url = https://github.com/cms-patatrack/alpaka.git
5 changes: 3 additions & 2 deletions CLUEstering/alpaka/AlpakaCore/CachingAllocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,9 @@ namespace clue {
return alpaka::allocBuf<std::byte, size_t>(device_, bytes);
} else if constexpr (std::is_same_v<Device, alpaka::DevCpu>) {
// allocate pinned host memory accessible by the queue's platform
return alpaka::allocMappedBuf<alpaka::Pltf<alpaka::Dev<Queue>>, std::byte, size_t>(
device_, bytes);
return alpaka::allocMappedBuf<alpaka::Platform<alpaka::Dev<Queue>>,
std::byte,
size_t>(device_, bytes);
} else {
// unsupported combination
static_assert(std::is_same_v<Device, alpaka::Dev<Queue>> or
Expand Down
2 changes: 1 addition & 1 deletion CLUEstering/alpaka/AlpakaCore/alpakaDevices.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace clue {

// alpaka host device
inline const alpaka_common::DevHost host =
alpaka::getDevByIdx<alpaka_common::PltfHost>(0u);
alpaka::getDevByIdx(alpaka::PlatformCpu{}, 0u);

// alpaka accelerator devices
template <typename TPlatform>
Expand Down
6 changes: 3 additions & 3 deletions CLUEstering/alpaka/AlpakaCore/getDeviceCachingAllocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace clue {
template <typename TDevice, typename TQueue>
auto allocate_device_allocators() {
using Allocator = CachingAllocator<TDevice, TQueue>;
auto const& devices = clue::enumerate<alpaka::Pltf<TDevice>>();
auto const& devices = clue::enumerate<alpaka::Platform<TDevice>>();
auto const size = devices.size();

// allocate the storage for the objects
Expand Down Expand Up @@ -57,9 +57,9 @@ namespace clue {

size_t const index = getDeviceIndex(device);

std::vector<TDevice> devs = alpaka::getDevs<alpaka::Pltf<TDevice>>();
std::vector<TDevice> devs = alpaka::getDevs<alpaka::Platform<TDevice>>();

assert(index < clue::enumerate<alpaka::Pltf<TDevice>>().size());
assert(index < clue::enumerate<alpaka::Platform<TDevice>>().size());

// the public interface is thread safe
return allocators[index];
Expand Down
4 changes: 2 additions & 2 deletions CLUEstering/alpaka/BindingModules/binding_cpu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace alpaka_serial_sync {
void listDevices(const std::string& backend) {
const char tab = '\t';
const std::vector<Device> devices = alpaka::getDevs<Platform>();
const std::vector<Device> devices = alpaka::getDevs(alpaka::Platform<Acc1D>());
if (devices.empty()) {
std::cout << "No devices found for the " << backend << " backend." << std::endl;
return;
Expand All @@ -34,7 +34,7 @@ namespace alpaka_serial_sync {
int Ndim,
size_t block_size,
size_t device_id) {
const auto dev_acc = alpaka::getDevByIdx<Acc1D>(device_id);
const auto dev_acc = alpaka::getDevByIdx(alpaka::Platform<Acc1D>{}, device_id);

// Create the queue
Queue queue_(dev_acc);
Expand Down
4 changes: 2 additions & 2 deletions CLUEstering/alpaka/BindingModules/binding_cpu_tbb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace alpaka_tbb_async {
void listDevices(const std::string& backend) {
const char tab = '\t';
const std::vector<Device> devices = alpaka::getDevs<Platform>();
const std::vector<Device> devices = alpaka::getDevs(alpaka::Platform<Acc1D>());
if (devices.empty()) {
std::cout << "No devices found for the " << backend << " backend." << std::endl;
return;
Expand All @@ -34,7 +34,7 @@ namespace alpaka_tbb_async {
int Ndim,
size_t block_size,
size_t device_id) {
const auto dev_acc = alpaka::getDevByIdx<Acc1D>(device_id);
const auto dev_acc = alpaka::getDevByIdx(alpaka::Platform<Acc1D>{}, device_id);

// Create the queue
Queue queue_(dev_acc);
Expand Down
4 changes: 2 additions & 2 deletions CLUEstering/alpaka/BindingModules/binding_gpu_cuda.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ using cms::alpakatools::initialise;
namespace alpaka_cuda_async {
void listDevices(const std::string& backend) {
const char tab = '\t';
const std::vector<Device> devices = alpaka::getDevs<Platform>();
const std::vector<Device> devices = alpaka::getDevs(alpaka::Platform<Acc1D>());
if (devices.empty()) {
std::cout << "No devices found for the " << backend << " backend." << std::endl;
return;
Expand All @@ -35,7 +35,7 @@ namespace alpaka_cuda_async {
int Ndim,
size_t block_size,
size_t device_id) {
const auto dev_acc = alpaka::getDevByIdx<Acc1D>(device_id);
const auto dev_acc = alpaka::getDevByIdx(alpaka::Platform<Acc1D>{}, device_id);

// Create the queue
Queue queue_(dev_acc);
Expand Down
4 changes: 2 additions & 2 deletions CLUEstering/alpaka/BindingModules/binding_gpu_hip.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace alpaka_rocm_async {
void listDevices(const std::string& backend) {
const char tab = '\t';
const std::vector<Device> devices = alpaka::getDevs<Platform>();
const std::vector<Device> devices = alpaka::getDevs(alpaka::Platform<Acc1D>());
if (devices.empty()) {
std::cout << "No devices found for the " << backend << " backend." << std::endl;
return;
Expand All @@ -33,7 +33,7 @@ namespace alpaka_rocm_async {
int Ndim,
size_t block_size,
size_t device_id) {
const auto dev_acc = alpaka::getDevByIdx<Acc1D>(device_id);
const auto dev_acc = alpaka::getDevByIdx(alpaka::Platform<Acc1D>{}, device_id);

// Create the queue
Queue queue_(dev_acc);
Expand Down
30 changes: 25 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.16.0)
project(CLUEstering LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

Expand All @@ -16,18 +16,33 @@ elseif(${CMAKE_BUILD_TYPE} STREQUAL "Release")
set(CMAKE_CXX_FLAGS "-O2")
endif()

# include alpaka extern subfolder
include_directories(extern/alpaka/include)
# include pybind11 extern subfolder
set(PYBIND11_FINDPYTHON ON)
set(PYBIND11_PYTHON_VERSION ">=3.8")
add_subdirectory(extern/pybind11)

find_package(Boost 1.75.0)
include(FetchContent)

find_package(alpaka)
if (NOT alpaka_FOUND)
FetchContent_Declare(
alpaka
GIT_REPOSITORY https://github.com/alpaka-group/alpaka.git
GIT_TAG develop
)

FetchContent_GetProperties(alpaka)
if(NOT alpaka_POPULATED)
FetchContent_Populate(alpaka)
endif()
set(alpaka_PATH ./build/_deps/alpaka-src/include)
else()
set(alpaka_PATH ${alpaka_INCLUDE_DIRS})
endif()

find_package(Boost 1.75.0)
# if boost is not found, it's fetched from the official boost repository
if(NOT Boost_FOUND)
include(FetchContent)
FetchContent_Declare(
boost
URL https://boostorg.jfrog.io/artifactory/main/release/1.76.0/source/boost_1_76_0.tar.gz
Expand Down Expand Up @@ -55,6 +70,7 @@ execute_process(COMMAND mkdir -p ./CLUEstering/lib)
# Convolutional Kernels compile convolutional kernel module
pybind11_add_module(CLUE_Convolutional_Kernels SHARED
./CLUEstering/alpaka/BindingModules/binding_kernels.cc)
target_include_directories(CLUE_Convolutional_Kernels PRIVATE ${alpaka_PATH})
# link boost
target_link_libraries(CLUE_Convolutional_Kernels PRIVATE ${Boost_LIBRARIES})
target_include_directories(CLUE_Convolutional_Kernels PRIVATE ${Boost_PATH})
Expand All @@ -79,6 +95,7 @@ endforeach()
# CPU Serial compile cpu serial module
pybind11_add_module(CLUE_CPU_Serial SHARED
./CLUEstering/alpaka/BindingModules/binding_cpu.cc)
target_include_directories(CLUE_CPU_Serial PRIVATE ${alpaka_PATH})
# link boost
target_link_libraries(CLUE_CPU_Serial PRIVATE ${Boost_LIBRARIES})
target_include_directories(CLUE_CPU_Serial PRIVATE ${Boost_PATH})
Expand Down Expand Up @@ -106,6 +123,7 @@ if(NOT ${SERIAL_ONLY})
# compile cpu tbb module
pybind11_add_module(CLUE_CPU_TBB SHARED
./CLUEstering/alpaka/BindingModules/binding_cpu_tbb.cc)
target_include_directories(CLUE_CPU_TBB PRIVATE ${alpaka_PATH})
target_link_libraries(CLUE_CPU_TBB PRIVATE ${Boost_LIBRARIES})
target_include_directories(CLUE_CPU_TBB PRIVATE ${Boost_PATH})
target_compile_options(
Expand Down Expand Up @@ -149,6 +167,7 @@ if((NOT ${CPU_ONLY}) AND (NOT ${SERIAL_ONLY}))
# compile gpu cuda module
pybind11_add_module(CLUE_GPU_CUDA SHARED
./CLUEstering/alpaka/BindingModules/binding_gpu_cuda.cc)
target_include_directories(CLUE_GPU_CUDA PRIVATE ${alpaka_PATH})
# link boost
target_link_libraries(CLUE_GPU_CUDA PRIVATE ${Boost_LIBRARIES})
target_include_directories(CLUE_GPU_CUDA PRIVATE ${Boost_PATH})
Expand Down Expand Up @@ -191,6 +210,7 @@ if((NOT ${CPU_ONLY}) AND (NOT ${SERIAL_ONLY}))
# compile gpu hip module
pybind11_add_module(CLUE_GPU_HIP SHARED
./CLUEstering/alpaka/BindingModules/binding_gpu_hip.cc)
target_include_directories(CLUE_GPU_HIP PRIVATE ${alpaka_PATH})
# link boost
target_link_libraries(CLUE_GPU_HIP PRIVATE ${Boost_LIBRARIES})
target_include_directories(CLUE_GPU_HIP PRIVATE ${Boost_PATH})
Expand Down
25 changes: 22 additions & 3 deletions benchmark/dataset_size/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,31 @@ elseif(${CMAKE_BUILD_TYPE} STREQUAL "Release")
endif()

# include alpaka extern subfolder
include_directories(../../extern/alpaka/include)
add_subdirectory(pybind11)

include(FetchContent)

find_package(alpaka)
if (NOT alpaka_FOUND)
FetchContent_Declare(
alpaka
GIT_REPOSITORY https://github.com/alpaka-group/alpaka.git
GIT_TAG develop
)

FetchContent_GetProperties(alpaka)
if(NOT alpaka_POPULATED)
FetchContent_Populate(alpaka)
endif()
set(alpaka_PATH ./build/_deps/alpaka-src/include)
else()
set(alpaka_PATH ${alpaka_INCLUDE_DIRS})
endif()

# look for boost
find_package(Boost 1.75.0)

# if boost is not found, it's fetched from the official boost repository
if(NOT Boost_FOUND)
include(FetchContent)
FetchContent_Declare(
boost
URL https://boostorg.jfrog.io/artifactory/main/release/1.76.0/source/boost_1_76_0.tar.gz
Expand All @@ -51,6 +67,7 @@ include_directories(../../CLUEstering/alpaka/)

# CPU Serial
add_executable(serial.out main.cc)
target_include_directories(serial.out PRIVATE ${alpaka_PATH})
target_link_libraries(serial.out PRIVATE pybind11::embed)
# link boost
target_link_libraries(serial.out PRIVATE ${Boost_LIBRARIES})
Expand All @@ -74,6 +91,7 @@ if(NOT ${SERIAL_ONLY})
if(TBB_FOUND)
# compile cpu tbb module
add_executable(tbb.out main.cc)
target_include_directories(tbb.out PRIVATE ${alpaka_PATH})
target_link_libraries(tbb.out PRIVATE pybind11::embed)
target_link_libraries(tbb.out PRIVATE ${Boost_LIBRARIES})
target_include_directories(tbb.out PRIVATE ${Boost_PATH})
Expand Down Expand Up @@ -114,6 +132,7 @@ if((NOT ${CPU_ONLY}) AND (NOT ${SERIAL_ONLY}))
set_source_files_properties(main.cc PROPERTIES LANGUAGE CUDA)
# compile gpu cuda module
add_executable(cuda.out main.cc)
target_include_directories(cuda.out PRIVATE ${alpaka_PATH})
target_link_libraries(cuda.out PRIVATE pybind11::embed)
# link boost
target_link_libraries(cuda.out PRIVATE ${Boost_LIBRARIES})
Expand Down
2 changes: 1 addition & 1 deletion benchmark/dataset_size/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ void to_csv(const TimeMeasures& measures, const std::string& filename) {

namespace ALPAKA_ACCELERATOR_NAMESPACE {
void run(const std::string& input_file) {
const auto dev_acc = alpaka::getDevByIdx<Acc1D>(0u);
const auto dev_acc = alpaka::getDevByIdx(alpaka::Platform<Acc1D>{}, 0u);
Queue queue_(dev_acc);
const auto data{read_csv<float, 2>(input_file)};
Points<2> h_points(data.first, data.second);
Expand Down
26 changes: 22 additions & 4 deletions benchmark/profiling/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,30 @@ elseif(${CMAKE_BUILD_TYPE} STREQUAL "Release")
set(CMAKE_CXX_FLAGS "-O2")
endif()

# include alpaka extern subfolder
include_directories(../../extern/alpaka/include)
include(FetchContent)

find_package(alpaka)
if (NOT alpaka_FOUND)
FetchContent_Declare(
alpaka
GIT_REPOSITORY https://github.com/alpaka-group/alpaka.git
GIT_TAG develop
)

FetchContent_GetProperties(alpaka)
if(NOT alpaka_POPULATED)
FetchContent_Populate(alpaka)
endif()
set(alpaka_PATH ./build/_deps/alpaka-src/include)
else()
set(alpaka_PATH ${alpaka_INCLUDE_DIRS})
endif()


# look for boost
find_package(Boost 1.75.0)

# if boost is not found, it's fetched from the official boost repository
if(NOT Boost_FOUND)
include(FetchContent)
FetchContent_Declare(
boost
URL https://boostorg.jfrog.io/artifactory/main/release/1.76.0/source/boost_1_76_0.tar.gz
Expand All @@ -50,6 +65,7 @@ include_directories(../../CLUEstering/alpaka/)

# CPU Serial
add_executable(serial.out main.cc)
target_include_directories(serial.out PRIVATE ${alpaka_PATH})
# link boost
target_link_libraries(serial.out PRIVATE ${Boost_LIBRARIES})
target_include_directories(serial.out PRIVATE ${Boost_PATH})
Expand All @@ -72,6 +88,7 @@ if(NOT ${SERIAL_ONLY})
if(TBB_FOUND)
# compile cpu tbb module
add_executable(tbb.out main.cc)
target_include_directories(tbb.out PRIVATE ${alpaka_PATH})
target_link_libraries(tbb.out PRIVATE ${Boost_LIBRARIES})
target_include_directories(tbb.out PRIVATE ${Boost_PATH})
target_compile_options(
Expand Down Expand Up @@ -111,6 +128,7 @@ if((NOT ${CPU_ONLY}) AND (NOT ${SERIAL_ONLY}))
set_source_files_properties(main.cc PROPERTIES LANGUAGE CUDA)
# compile gpu cuda module
add_executable(cuda.out main.cc)
target_include_directories(cuda.out PRIVATE ${alpaka_PATH})
# link boost
target_link_libraries(cuda.out PRIVATE ${Boost_LIBRARIES})
target_include_directories(cuda.out PRIVATE ${Boost_PATH})
Expand Down
2 changes: 1 addition & 1 deletion benchmark/profiling/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace ALPAKA_ACCELERATOR_NAMESPACE {
void run(const std::string& input_file) {
const auto dev_acc = alpaka::getDevByIdx<Acc1D>(0u);
const auto dev_acc = alpaka::getDevByIdx(alpaka::Platform<Acc1D>{}, 0u);
Queue queue_(dev_acc);
const auto data{read_csv<float, 2>(input_file)};
Points<2> h_points(data.first, data.second);
Expand Down
18 changes: 18 additions & 0 deletions docker/alpaka_preinstalled/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

FROM ubuntu:22.04

RUN apt-get update && apt-get install -y \
python3-dev \
python3-pip \
cmake \
g++ \
libboost-all-dev \
git

RUN git clone https://github.com/alpaka-group/alpaka.git \
&& cd alpaka \
&& cmake -B build -S . \
&& cmake --build build \
&& cmake --install build

CMD ["/bin/bash"]
1 change: 0 additions & 1 deletion extern/alpaka
Submodule alpaka deleted from 5573fc
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from setuptools import setup
import subprocess

__version__ = "2.2.11"
__version__ = "2.2.12"

this_directory = Path(__file__).parent
long_description = (this_directory/'README.md').read_text()
Expand Down

0 comments on commit 389b73a

Please sign in to comment.