Skip to content

Commit

Permalink
Update alpakaconfig (cms-patatrack#70)
Browse files Browse the repository at this point in the history
* Use alpaka ENABLED flag instead of PRESENT

* Rename alpaka acc namespace to avoid conflict with cmssw

* Update platform aliases

* Move definition of accelerator namespace

* Update namespace names in benchmarking scripts

* Update cuda alpakacore

* Update hip alpakacore

* Update package version
  • Loading branch information
sbaldu authored Jan 8, 2025
1 parent d8e476d commit e3c5036
Show file tree
Hide file tree
Showing 14 changed files with 69 additions and 63 deletions.
4 changes: 2 additions & 2 deletions CLUEstering/alpaka/AlpakaCore/CachedBufAlloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ namespace clue {
auto deleter = [alloc = &allocator](TElem* ptr) { alloc->free(ptr); };

return alpaka::BufCudaRt<TElem, TDim, TIdx>(
dev, reinterpret_cast<TElem*>(memPtr), std::move(deleter), pitchBytes, extent);
dev, reinterpret_cast<TElem*>(memPtr), std::move(deleter), extent, pitchBytes);
}
};

Expand Down Expand Up @@ -153,7 +153,7 @@ namespace clue {
auto deleter = [alloc = &allocator](TElem* ptr) { alloc->free(ptr); };

return alpaka::BufHipRt<TElem, TDim, TIdx>(
dev, reinterpret_cast<TElem*>(memPtr), std::move(deleter), pitchBytes, extent);
dev, reinterpret_cast<TElem*>(memPtr), std::move(deleter), extent, pitchBytes);
}
};

Expand Down
7 changes: 4 additions & 3 deletions CLUEstering/alpaka/AlpakaCore/CachingAllocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,10 @@ 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::Platform<alpaka::Dev<Queue>>,
std::byte,
size_t>(device_, bytes);
using Platform = alpaka::Platform<alpaka::Dev<Queue>>;
return alpaka::
allocMappedBuf<alpaka::Platform<alpaka::Dev<Queue>>, std::byte, size_t>(
device_, ::clue::platform<Platform>(), bytes);
} else {
// unsupported combination
static_assert(std::is_same_v<Device, alpaka::Dev<Queue>> or
Expand Down
56 changes: 21 additions & 35 deletions CLUEstering/alpaka/AlpakaCore/alpakaConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#pragma once

#include "alpakaFwd.h"
#include <alpaka/alpaka.hpp>

namespace alpaka_common {

Expand Down Expand Up @@ -30,15 +31,15 @@ namespace alpaka_common {

// host types
using DevHost = alpaka::DevCpu;
using PltfHost = alpaka::PltfCpu;
using PlatformHost = alpaka::PlatformCpu;

} // namespace alpaka_common

#ifdef ALPAKA_ACC_GPU_CUDA_PRESENT
#ifdef ALPAKA_ACC_GPU_CUDA_ENABLED
namespace alpaka_cuda_async {
using namespace alpaka_common;

using Platform = alpaka::PltfCudaRt;
using Platform = alpaka::PlatformCudaRt;
using Device = alpaka::DevCudaRt;
using Queue = alpaka::QueueCudaRtNonBlocking;
using Event = alpaka::EventCudaRt;
Expand All @@ -49,19 +50,16 @@ namespace alpaka_cuda_async {
using Acc2D = Acc<Dim2D>;
using Acc3D = Acc<Dim3D>;

#define ALPAKA_ACCELERATOR_NAMESPACE_CLUE alpaka_cuda_async
} // namespace alpaka_cuda_async

#endif // ALPAKA_ACC_GPU_CUDA_PRESENT

#ifdef ALPAKA_ACC_GPU_CUDA_ASYNC_BACKEND
#define ALPAKA_ACCELERATOR_NAMESPACE alpaka_cuda_async
#endif // ALPAKA_ACC_GPU_CUDA_ASYNC_BACKEND

#ifdef ALPAKA_ACC_GPU_HIP_PRESENT
#ifdef ALPAKA_ACC_GPU_HIP_ENABLED
namespace alpaka_rocm_async {
using namespace alpaka_common;

using Platform = alpaka::PltfHipRt;
using Platform = alpaka::PlatformHipRt;
using Device = alpaka::DevHipRt;
using Queue = alpaka::QueueHipRtNonBlocking;
using Event = alpaka::EventHipRt;
Expand All @@ -72,19 +70,16 @@ namespace alpaka_rocm_async {
using Acc2D = Acc<Dim2D>;
using Acc3D = Acc<Dim3D>;

#define ALPAKA_ACCELERATOR_NAMESPACE_CLUE alpaka_rocm_async
} // namespace alpaka_rocm_async

#endif // ALPAKA_ACC_GPU_HIP_PRESENT

#ifdef ALPAKA_ACC_GPU_HIP_ASYNC_BACKEND
#define ALPAKA_ACCELERATOR_NAMESPACE alpaka_rocm_async
#endif // ALPAKA_ACC_GPU_HIP_ASYNC_BACKEND
#endif // ALPAKA_ACC_GPU_HIP_ENABLED

#ifdef ALPAKA_ACC_CPU_B_SEQ_T_SEQ_PRESENT
#ifdef ALPAKA_ACC_CPU_B_SEQ_T_SEQ_ENABLED
namespace alpaka_serial_sync {
using namespace alpaka_common;

using Platform = alpaka::PltfCpu;
using Platform = alpaka::PlatformCpu;
using Device = alpaka::DevCpu;
using Queue = alpaka::QueueCpuBlocking;
using Event = alpaka::EventCpu;
Expand All @@ -95,19 +90,16 @@ namespace alpaka_serial_sync {
using Acc2D = Acc<Dim2D>;
using Acc3D = Acc<Dim3D>;

#define ALPAKA_ACCELERATOR_NAMESPACE_CLUE alpaka_serial_sync
} // namespace alpaka_serial_sync

#endif // ALPAKA_ACC_CPU_B_SEQ_T_SEQ_PRESENT

#ifdef ALPAKA_ACC_CPU_B_SEQ_T_SEQ_SYNC_BACKEND
#define ALPAKA_ACCELERATOR_NAMESPACE alpaka_serial_sync
#endif // ALPAKA_ACC_CPU_B_SEQ_T_SEQ_SYNC_BACKEND
#endif // ALPAKA_ACC_CPU_B_SEQ_T_SEQ_ENABLED

#ifdef ALPAKA_ACC_CPU_B_TBB_T_SEQ_PRESENT
#ifdef ALPAKA_ACC_CPU_B_TBB_T_SEQ_ENABLED
namespace alpaka_tbb_async {
using namespace alpaka_common;

using Platform = alpaka::PltfCpu;
using Platform = alpaka::PlatformCpu;
using Device = alpaka::DevCpu;
using Queue = alpaka::QueueCpuNonBlocking;
using Event = alpaka::EventCpu;
Expand All @@ -118,19 +110,16 @@ namespace alpaka_tbb_async {
using Acc2D = Acc<Dim2D>;
using Acc3D = Acc<Dim3D>;

#define ALPAKA_ACCELERATOR_NAMESPACE_CLUE alpaka_tbb_async
} // namespace alpaka_tbb_async

#endif // ALPAKA_ACC_CPU_B_TBB_T_SEQ_PRESENT
#endif // ALPAKA_ACC_CPU_B_TBB_T_SEQ_ENABLED

#ifdef ALPAKA_ACC_CPU_B_TBB_T_SEQ_ASYNC_BACKEND
#define ALPAKA_ACCELERATOR_NAMESPACE alpaka_tbb_async
#endif // ALPAKA_ACC_CPU_B_TBB_T_SEQ_ASYNC_BACKEND

#ifdef ALPAKA_ACC_CPU_B_OMP2_T_SEQ_PRESENT
#ifdef ALPAKA_ACC_CPU_B_OMP2_T_SEQ_ENABLED
namespace alpaka_omp2_async {
using namespace alpaka_common;

using Platform = alpaka::PltfCpu;
using Platform = alpaka::PlatformCpu;
using Device = alpaka::DevCpu;
using Queue = alpaka::QueueCpuBlocking;
using Event = alpaka::EventCpu;
Expand All @@ -141,10 +130,7 @@ namespace alpaka_omp2_async {
using Acc2D = Acc<Dim2D>;
using Acc3D = Acc<Dim3D>;

#define ALPAKA_ACCELERATOR_NAMESPACE_CLUE alpaka_omp2_async
} // namespace alpaka_omp2_async

#endif // ALPAKA_ACC_CPU_B_OMP2_T_SEQ_PRESENT

#ifdef ALPAKA_ACC_CPU_B_OMP2_T_SEQ_ASYNC_BACKEND
#define ALPAKA_ACCELERATOR_NAMESPACE alpaka_omp2_async
#endif // ALPAKA_ACC_CPU_B_OMP2_T_SEQ_ASYNC_BACKEND
#endif // ALPAKA_ACC_CPU_B_OMP2_T_SEQ_ENABLED
23 changes: 19 additions & 4 deletions CLUEstering/alpaka/AlpakaCore/alpakaDevices.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,29 @@
#include "getDeviceIndex.h"

namespace clue {
// returns the alpaka accelerator platform
template <typename TPlatform, typename = std::enable_if_t<alpaka::isPlatform<TPlatform>>>
inline TPlatform const& platform() {
// initialise the platform the first time that this function is called
static const auto platform = TPlatform{};
return platform;
}

// return the alpaka accelerator devices for the given platform
template <typename TPlatform, typename = std::enable_if_t<alpaka::isPlatform<TPlatform>>>
inline std::vector<alpaka::Dev<TPlatform>> const& devices() {
// enumerate all devices the first time that this function is called
static const auto devices = alpaka::getDevs(platform<TPlatform>());
return devices;
}

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

// alpaka accelerator devices
template <typename TPlatform>
inline std::vector<alpaka::Dev<TPlatform>> devices;
/* template <typename TPlatform> */
/* inline std::vector<alpaka::Dev<TPlatform>> devices; */

template <typename TPlatform>
std::vector<alpaka::Dev<TPlatform>> enumerate() {
Expand All @@ -27,10 +42,10 @@ namespace clue {
using Platform = TPlatform;

std::vector<Device> devices;
uint32_t n = alpaka::getDevCount<Platform>();
uint32_t n = alpaka::getDevCount(Platform{});
devices.reserve(n);
for (uint32_t i = 0; i < n; ++i) {
devices.push_back(alpaka::getDevByIdx<Platform>(i));
devices.push_back(alpaka::getDevByIdx(Platform{}, i));
assert(getDeviceIndex(devices.back()) == static_cast<int>(i));
}
return devices;
Expand Down
2 changes: 1 addition & 1 deletion CLUEstering/alpaka/AlpakaCore/getDeviceCachingAllocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ namespace clue {

size_t const index = getDeviceIndex(device);

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

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

Expand Down
4 changes: 2 additions & 2 deletions CLUEstering/alpaka/CLUE/CLUEAlgoAlpaka.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

using clue::VecArray;

namespace ALPAKA_ACCELERATOR_NAMESPACE {
namespace ALPAKA_ACCELERATOR_NAMESPACE_CLUE {

template <uint8_t Ndim>
class CLUEAlgoAlpaka {
Expand Down Expand Up @@ -247,4 +247,4 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {

return {h_points.m_clusterIndex, h_points.m_isSeed};
}
} // namespace ALPAKA_ACCELERATOR_NAMESPACE
} // namespace ALPAKA_ACCELERATOR_NAMESPACE_CLUE
4 changes: 2 additions & 2 deletions CLUEstering/alpaka/CLUE/CLUEAlpakaKernels.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

using clue::VecArray;

namespace ALPAKA_ACCELERATOR_NAMESPACE {
namespace ALPAKA_ACCELERATOR_NAMESPACE_CLUE {

constexpr int32_t max_followers{100};
constexpr int32_t reserve{1000000};
Expand Down Expand Up @@ -349,4 +349,4 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
});
}
};
} // namespace ALPAKA_ACCELERATOR_NAMESPACE
} // namespace ALPAKA_ACCELERATOR_NAMESPACE_CLUE
4 changes: 2 additions & 2 deletions CLUEstering/alpaka/CLUE/Run.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include "CLUEAlgoAlpaka.h"

namespace ALPAKA_ACCELERATOR_NAMESPACE {
namespace ALPAKA_ACCELERATOR_NAMESPACE_CLUE {

template <uint8_t Ndim, typename Kernel>
std::vector<std::vector<int>> run(float dc,
Expand All @@ -26,4 +26,4 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
return algo.make_clusters(h_points, d_points, kernel, queue_, block_size);
}

}; // namespace ALPAKA_ACCELERATOR_NAMESPACE
}; // namespace ALPAKA_ACCELERATOR_NAMESPACE_CLUE
2 changes: 2 additions & 0 deletions CLUEstering/alpaka/DataFormats/alpaka/AlpakaVecArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
// Author: Felice Pantaleo, CERN
//

#include <alpaka/alpaka.hpp>

namespace clue {

template <class T, int maxSize>
Expand Down
4 changes: 2 additions & 2 deletions CLUEstering/alpaka/DataFormats/alpaka/PointsAlpaka.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

using clue::VecArray;

namespace ALPAKA_ACCELERATOR_NAMESPACE {
namespace ALPAKA_ACCELERATOR_NAMESPACE_CLUE {

template <uint8_t Ndim>
class PointsAlpaka {
Expand Down Expand Up @@ -71,4 +71,4 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
private:
clue::device_buffer<Device, PointsAlpakaView> view_dev;
};
} // namespace ALPAKA_ACCELERATOR_NAMESPACE
} // namespace ALPAKA_ACCELERATOR_NAMESPACE_CLUE
4 changes: 2 additions & 2 deletions CLUEstering/alpaka/DataFormats/alpaka/TilesAlpaka.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ using clue::VecArray;
constexpr uint32_t max_tile_depth{1 << 10};
constexpr uint32_t max_n_tiles{1 << 15};

namespace ALPAKA_ACCELERATOR_NAMESPACE {
namespace ALPAKA_ACCELERATOR_NAMESPACE_CLUE {

template <uint8_t Ndim>
class CoordinateExtremes {
Expand Down Expand Up @@ -136,4 +136,4 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
float tile_size[Ndim];
VecArray<VecArray<uint32_t, max_tile_depth>, max_n_tiles> m_tiles;
};
} // namespace ALPAKA_ACCELERATOR_NAMESPACE
} // namespace ALPAKA_ACCELERATOR_NAMESPACE_CLUE
6 changes: 3 additions & 3 deletions benchmark/dataset_size/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void to_csv(const TimeMeasures& measures, const std::string& filename) {
file.close();
}

namespace ALPAKA_ACCELERATOR_NAMESPACE {
namespace ALPAKA_ACCELERATOR_NAMESPACE_CLUE {
void run(const std::string& input_file) {
const auto dev_acc = alpaka::getDevByIdx(alpaka::Platform<Acc1D>{}, 0u);
Queue queue_(dev_acc);
Expand All @@ -99,9 +99,9 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
auto result =
algo.make_clusters(h_points, d_points, FlatKernel{.5f}, queue_, block_size);
}
}; // namespace ALPAKA_ACCELERATOR_NAMESPACE
}; // namespace ALPAKA_ACCELERATOR_NAMESPACE_CLUE

namespace cluetest = ALPAKA_ACCELERATOR_NAMESPACE;
namespace cluetest = ALPAKA_ACCELERATOR_NAMESPACE_CLUE;

int main(int argc, char* argv[]) {
auto min = std::stoi(argv[1]);
Expand Down
10 changes: 6 additions & 4 deletions benchmark/profiling/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#include "read_csv.hpp"

namespace ALPAKA_ACCELERATOR_NAMESPACE {
namespace ALPAKA_ACCELERATOR_NAMESPACE_CLUE {
void run(const std::string& input_file) {
const auto dev_acc = alpaka::getDevByIdx(alpaka::Platform<Acc1D>{}, 0u);
Queue queue_(dev_acc);
Expand All @@ -24,11 +24,13 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
CLUEAlgoAlpaka<2> algo(dc, rhoc, outlier, pPBin, queue_);

const std::size_t block_size{256};
auto result = algo.make_clusters(h_points, d_points, FlatKernel{.5f}, queue_, block_size);
auto result =
algo.make_clusters(h_points, d_points, FlatKernel{.5f}, queue_, block_size);
}
}; // namespace ALPAKA_ACCELERATOR_NAMESPACE
}; // namespace ALPAKA_ACCELERATOR_NAMESPACE_CLUE

int main(int argc, char* argv[]) {
auto input_file{std::string(argv[1])};
ALPAKA_ACCELERATOR_NAMESPACE::run(input_file);
using ALPAKA_ACCELERATOR_NAMESPACE_CLUE;
run(input_file);
}
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.3.0"
__version__ = "2.3.1"

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

0 comments on commit e3c5036

Please sign in to comment.