From 389b73aa11af56454b789d57b3af1c40bc0489f7 Mon Sep 17 00:00:00 2001 From: Simone Balducci <93096843+sbaldu@users.noreply.github.com> Date: Mon, 23 Dec 2024 10:18:22 +0100 Subject: [PATCH] Update alpaka dependency (#69) * 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 --- .gitmodules | 3 -- .../alpaka/AlpakaCore/CachingAllocator.h | 5 ++-- CLUEstering/alpaka/AlpakaCore/alpakaDevices.h | 2 +- .../AlpakaCore/getDeviceCachingAllocator.h | 6 ++-- .../alpaka/BindingModules/binding_cpu.cc | 4 +-- .../alpaka/BindingModules/binding_cpu_tbb.cc | 4 +-- .../alpaka/BindingModules/binding_gpu_cuda.cc | 4 +-- .../alpaka/BindingModules/binding_gpu_hip.cc | 4 +-- CMakeLists.txt | 30 +++++++++++++++---- benchmark/dataset_size/CMakeLists.txt | 25 ++++++++++++++-- benchmark/dataset_size/main.cc | 2 +- benchmark/profiling/CMakeLists.txt | 26 +++++++++++++--- benchmark/profiling/main.cc | 2 +- docker/alpaka_preinstalled/Dockerfile | 18 +++++++++++ extern/alpaka | 1 - setup.py | 2 +- 16 files changed, 105 insertions(+), 33 deletions(-) create mode 100644 docker/alpaka_preinstalled/Dockerfile delete mode 160000 extern/alpaka diff --git a/.gitmodules b/.gitmodules index e8f8e590..3d07ed7c 100644 --- a/.gitmodules +++ b/.gitmodules @@ -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 diff --git a/CLUEstering/alpaka/AlpakaCore/CachingAllocator.h b/CLUEstering/alpaka/AlpakaCore/CachingAllocator.h index 67da1090..ae95c0e6 100644 --- a/CLUEstering/alpaka/AlpakaCore/CachingAllocator.h +++ b/CLUEstering/alpaka/AlpakaCore/CachingAllocator.h @@ -334,8 +334,9 @@ namespace clue { return alpaka::allocBuf(device_, bytes); } else if constexpr (std::is_same_v) { // allocate pinned host memory accessible by the queue's platform - return alpaka::allocMappedBuf>, std::byte, size_t>( - device_, bytes); + return alpaka::allocMappedBuf>, + std::byte, + size_t>(device_, bytes); } else { // unsupported combination static_assert(std::is_same_v> or diff --git a/CLUEstering/alpaka/AlpakaCore/alpakaDevices.h b/CLUEstering/alpaka/AlpakaCore/alpakaDevices.h index 7b033125..9f44de44 100644 --- a/CLUEstering/alpaka/AlpakaCore/alpakaDevices.h +++ b/CLUEstering/alpaka/AlpakaCore/alpakaDevices.h @@ -13,7 +13,7 @@ namespace clue { // alpaka host device inline const alpaka_common::DevHost host = - alpaka::getDevByIdx(0u); + alpaka::getDevByIdx(alpaka::PlatformCpu{}, 0u); // alpaka accelerator devices template diff --git a/CLUEstering/alpaka/AlpakaCore/getDeviceCachingAllocator.h b/CLUEstering/alpaka/AlpakaCore/getDeviceCachingAllocator.h index 2e51d2b8..36a1c68f 100644 --- a/CLUEstering/alpaka/AlpakaCore/getDeviceCachingAllocator.h +++ b/CLUEstering/alpaka/AlpakaCore/getDeviceCachingAllocator.h @@ -18,7 +18,7 @@ namespace clue { template auto allocate_device_allocators() { using Allocator = CachingAllocator; - auto const& devices = clue::enumerate>(); + auto const& devices = clue::enumerate>(); auto const size = devices.size(); // allocate the storage for the objects @@ -57,9 +57,9 @@ namespace clue { size_t const index = getDeviceIndex(device); - std::vector devs = alpaka::getDevs>(); + std::vector devs = alpaka::getDevs>(); - assert(index < clue::enumerate>().size()); + assert(index < clue::enumerate>().size()); // the public interface is thread safe return allocators[index]; diff --git a/CLUEstering/alpaka/BindingModules/binding_cpu.cc b/CLUEstering/alpaka/BindingModules/binding_cpu.cc index 96db565f..69682871 100644 --- a/CLUEstering/alpaka/BindingModules/binding_cpu.cc +++ b/CLUEstering/alpaka/BindingModules/binding_cpu.cc @@ -11,7 +11,7 @@ namespace alpaka_serial_sync { void listDevices(const std::string& backend) { const char tab = '\t'; - const std::vector devices = alpaka::getDevs(); + const std::vector devices = alpaka::getDevs(alpaka::Platform()); if (devices.empty()) { std::cout << "No devices found for the " << backend << " backend." << std::endl; return; @@ -34,7 +34,7 @@ namespace alpaka_serial_sync { int Ndim, size_t block_size, size_t device_id) { - const auto dev_acc = alpaka::getDevByIdx(device_id); + const auto dev_acc = alpaka::getDevByIdx(alpaka::Platform{}, device_id); // Create the queue Queue queue_(dev_acc); diff --git a/CLUEstering/alpaka/BindingModules/binding_cpu_tbb.cc b/CLUEstering/alpaka/BindingModules/binding_cpu_tbb.cc index 0e70ffb1..965c9ad2 100644 --- a/CLUEstering/alpaka/BindingModules/binding_cpu_tbb.cc +++ b/CLUEstering/alpaka/BindingModules/binding_cpu_tbb.cc @@ -11,7 +11,7 @@ namespace alpaka_tbb_async { void listDevices(const std::string& backend) { const char tab = '\t'; - const std::vector devices = alpaka::getDevs(); + const std::vector devices = alpaka::getDevs(alpaka::Platform()); if (devices.empty()) { std::cout << "No devices found for the " << backend << " backend." << std::endl; return; @@ -34,7 +34,7 @@ namespace alpaka_tbb_async { int Ndim, size_t block_size, size_t device_id) { - const auto dev_acc = alpaka::getDevByIdx(device_id); + const auto dev_acc = alpaka::getDevByIdx(alpaka::Platform{}, device_id); // Create the queue Queue queue_(dev_acc); diff --git a/CLUEstering/alpaka/BindingModules/binding_gpu_cuda.cc b/CLUEstering/alpaka/BindingModules/binding_gpu_cuda.cc index daaef9ff..5c2e017b 100644 --- a/CLUEstering/alpaka/BindingModules/binding_gpu_cuda.cc +++ b/CLUEstering/alpaka/BindingModules/binding_gpu_cuda.cc @@ -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 devices = alpaka::getDevs(); + const std::vector devices = alpaka::getDevs(alpaka::Platform()); if (devices.empty()) { std::cout << "No devices found for the " << backend << " backend." << std::endl; return; @@ -35,7 +35,7 @@ namespace alpaka_cuda_async { int Ndim, size_t block_size, size_t device_id) { - const auto dev_acc = alpaka::getDevByIdx(device_id); + const auto dev_acc = alpaka::getDevByIdx(alpaka::Platform{}, device_id); // Create the queue Queue queue_(dev_acc); diff --git a/CLUEstering/alpaka/BindingModules/binding_gpu_hip.cc b/CLUEstering/alpaka/BindingModules/binding_gpu_hip.cc index f7a8ce31..faa4f701 100644 --- a/CLUEstering/alpaka/BindingModules/binding_gpu_hip.cc +++ b/CLUEstering/alpaka/BindingModules/binding_gpu_hip.cc @@ -10,7 +10,7 @@ namespace alpaka_rocm_async { void listDevices(const std::string& backend) { const char tab = '\t'; - const std::vector devices = alpaka::getDevs(); + const std::vector devices = alpaka::getDevs(alpaka::Platform()); if (devices.empty()) { std::cout << "No devices found for the " << backend << " backend." << std::endl; return; @@ -33,7 +33,7 @@ namespace alpaka_rocm_async { int Ndim, size_t block_size, size_t device_id) { - const auto dev_acc = alpaka::getDevByIdx(device_id); + const auto dev_acc = alpaka::getDevByIdx(alpaka::Platform{}, device_id); // Create the queue Queue queue_(dev_acc); diff --git a/CMakeLists.txt b/CMakeLists.txt index 36f72a88..49c56c74 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) @@ -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 @@ -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}) @@ -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}) @@ -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( @@ -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}) @@ -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}) diff --git a/benchmark/dataset_size/CMakeLists.txt b/benchmark/dataset_size/CMakeLists.txt index 000b023c..c5a7f5a1 100644 --- a/benchmark/dataset_size/CMakeLists.txt +++ b/benchmark/dataset_size/CMakeLists.txt @@ -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 @@ -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}) @@ -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}) @@ -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}) diff --git a/benchmark/dataset_size/main.cc b/benchmark/dataset_size/main.cc index 981f4eec..14f05953 100644 --- a/benchmark/dataset_size/main.cc +++ b/benchmark/dataset_size/main.cc @@ -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(0u); + const auto dev_acc = alpaka::getDevByIdx(alpaka::Platform{}, 0u); Queue queue_(dev_acc); const auto data{read_csv(input_file)}; Points<2> h_points(data.first, data.second); diff --git a/benchmark/profiling/CMakeLists.txt b/benchmark/profiling/CMakeLists.txt index 3b31fc28..37fb837d 100644 --- a/benchmark/profiling/CMakeLists.txt +++ b/benchmark/profiling/CMakeLists.txt @@ -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 @@ -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}) @@ -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( @@ -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}) diff --git a/benchmark/profiling/main.cc b/benchmark/profiling/main.cc index af15af8d..982782dc 100644 --- a/benchmark/profiling/main.cc +++ b/benchmark/profiling/main.cc @@ -13,7 +13,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { void run(const std::string& input_file) { - const auto dev_acc = alpaka::getDevByIdx(0u); + const auto dev_acc = alpaka::getDevByIdx(alpaka::Platform{}, 0u); Queue queue_(dev_acc); const auto data{read_csv(input_file)}; Points<2> h_points(data.first, data.second); diff --git a/docker/alpaka_preinstalled/Dockerfile b/docker/alpaka_preinstalled/Dockerfile new file mode 100644 index 00000000..01a88a36 --- /dev/null +++ b/docker/alpaka_preinstalled/Dockerfile @@ -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"] diff --git a/extern/alpaka b/extern/alpaka deleted file mode 160000 index 5573fc35..00000000 --- a/extern/alpaka +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 5573fc351cc1de8d4ffe0db092ad1b3eb9eae177 diff --git a/setup.py b/setup.py index 6d4e9027..ffdca2dc 100644 --- a/setup.py +++ b/setup.py @@ -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()