Skip to content

Commit

Permalink
renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
jorisvandenbossche committed Mar 27, 2024
1 parent 1ac0c76 commit a5a6f6c
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 37 deletions.
10 changes: 5 additions & 5 deletions cpp/src/arrow/buffer_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1027,13 +1027,13 @@ TEST(TestDeviceRegistry, Basics) {
// Test the error cases for the device registry

// CPU is already registered
ASSERT_RAISES(KeyError, RegisterDeviceMemoryManager(
DeviceAllocationType::kCPU, [](int64_t device_id) {
return default_cpu_memory_manager();
}));
ASSERT_RAISES(KeyError,
RegisterDeviceMapper(DeviceAllocationType::kCPU, [](int64_t device_id) {
return default_cpu_memory_manager();
}));

// VPI is not registered
ASSERT_RAISES(KeyError, GetDeviceMemoryManager(DeviceAllocationType::kVPI));
ASSERT_RAISES(KeyError, GetDeviceMapper(DeviceAllocationType::kVPI));
}

} // namespace arrow
8 changes: 4 additions & 4 deletions cpp/src/arrow/c/bridge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1967,10 +1967,10 @@ Result<std::shared_ptr<RecordBatch>> ImportRecordBatch(struct ArrowArray* array,
return ImportRecordBatch(array, *maybe_schema);
}

Result<std::shared_ptr<MemoryManager>> DefaultDeviceMapper(ArrowDeviceType device_type,
int64_t device_id) {
ARROW_ASSIGN_OR_RAISE(auto mapper, GetDeviceMemoryManager(
static_cast<DeviceAllocationType>(device_type)));
Result<std::shared_ptr<MemoryManager>> DefaultDeviceMemoryMapper(
ArrowDeviceType device_type, int64_t device_id) {
ARROW_ASSIGN_OR_RAISE(auto mapper,
GetDeviceMapper(static_cast<DeviceAllocationType>(device_type)));
return mapper(device_id);
}

Expand Down
12 changes: 6 additions & 6 deletions cpp/src/arrow/c/bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@ using DeviceMemoryMapper =
std::function<Result<std::shared_ptr<MemoryManager>>(ArrowDeviceType, int64_t)>;

ARROW_EXPORT
Result<std::shared_ptr<MemoryManager>> DefaultDeviceMapper(ArrowDeviceType device_type,
int64_t device_id);
Result<std::shared_ptr<MemoryManager>> DefaultDeviceMemoryMapper(
ArrowDeviceType device_type, int64_t device_id);

/// \brief EXPERIMENTAL: Import C++ device array from the C data interface.
///
Expand All @@ -236,7 +236,7 @@ Result<std::shared_ptr<MemoryManager>> DefaultDeviceMapper(ArrowDeviceType devic
ARROW_EXPORT
Result<std::shared_ptr<Array>> ImportDeviceArray(
struct ArrowDeviceArray* array, std::shared_ptr<DataType> type,
const DeviceMemoryMapper& mapper = DefaultDeviceMapper);
const DeviceMemoryMapper& mapper = DefaultDeviceMemoryMapper);

/// \brief EXPERIMENTAL: Import C++ device array and its type from the C data interface.
///
Expand All @@ -253,7 +253,7 @@ Result<std::shared_ptr<Array>> ImportDeviceArray(
ARROW_EXPORT
Result<std::shared_ptr<Array>> ImportDeviceArray(
struct ArrowDeviceArray* array, struct ArrowSchema* type,
const DeviceMemoryMapper& mapper = DefaultDeviceMapper);
const DeviceMemoryMapper& mapper = DefaultDeviceMemoryMapper);

/// \brief EXPERIMENTAL: Import C++ record batch with buffers on a device from the C data
/// interface.
Expand All @@ -271,7 +271,7 @@ Result<std::shared_ptr<Array>> ImportDeviceArray(
ARROW_EXPORT
Result<std::shared_ptr<RecordBatch>> ImportDeviceRecordBatch(
struct ArrowDeviceArray* array, std::shared_ptr<Schema> schema,
const DeviceMemoryMapper& mapper = DefaultDeviceMapper);
const DeviceMemoryMapper& mapper = DefaultDeviceMemoryMapper);

/// \brief EXPERIMENTAL: Import C++ record batch with buffers on a device and its schema
/// from the C data interface.
Expand All @@ -291,7 +291,7 @@ Result<std::shared_ptr<RecordBatch>> ImportDeviceRecordBatch(
ARROW_EXPORT
Result<std::shared_ptr<RecordBatch>> ImportDeviceRecordBatch(
struct ArrowDeviceArray* array, struct ArrowSchema* schema,
const DeviceMemoryMapper& mapper = DefaultDeviceMapper);
const DeviceMemoryMapper& mapper = DefaultDeviceMemoryMapper);

/// @}

Expand Down
30 changes: 15 additions & 15 deletions cpp/src/arrow/device.cc
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,11 @@ std::shared_ptr<MemoryManager> CPUDevice::default_memory_manager() {

namespace {

class DeviceMemoryManagerRegistryImpl {
class DeviceMapperRegistryImpl {
public:
DeviceMemoryManagerRegistryImpl() {}
DeviceMapperRegistryImpl() {}

Status RegisterDevice(DeviceAllocationType device_type, MemoryMapper memory_mapper) {
Status RegisterDevice(DeviceAllocationType device_type, DeviceMapper memory_mapper) {
std::lock_guard<std::mutex> lock(lock_);
auto [_, inserted] = registry_.try_emplace(device_type, std::move(memory_mapper));
if (!inserted) {
Expand All @@ -286,7 +286,7 @@ class DeviceMemoryManagerRegistryImpl {
return Status::OK();
}

Result<MemoryMapper> GetMemoryManager(DeviceAllocationType device_type) {
Result<DeviceMapper> GetMapper(DeviceAllocationType device_type) {
std::lock_guard<std::mutex> lock(lock_);
auto it = registry_.find(device_type);
if (it == registry_.end()) {
Expand All @@ -298,38 +298,38 @@ class DeviceMemoryManagerRegistryImpl {

private:
std::mutex lock_;
std::unordered_map<DeviceAllocationType, MemoryMapper> registry_;
std::unordered_map<DeviceAllocationType, DeviceMapper> registry_;
};

Result<std::shared_ptr<MemoryManager>> DefaultCPUMemoryMapper(int64_t device_id) {
Result<std::shared_ptr<MemoryManager>> DefaultCPUDeviceMapper(int64_t device_id) {
return default_cpu_memory_manager();
}

static std::unique_ptr<DeviceMemoryManagerRegistryImpl> CreateDeviceRegistry() {
auto registry = std::make_unique<DeviceMemoryManagerRegistryImpl>();
static std::unique_ptr<DeviceMapperRegistryImpl> CreateDeviceRegistry() {
auto registry = std::make_unique<DeviceMapperRegistryImpl>();

// Always register the CPU device
DCHECK_OK(registry->RegisterDevice(DeviceAllocationType::kCPU, DefaultCPUMemoryMapper));
DCHECK_OK(registry->RegisterDevice(DeviceAllocationType::kCPU, DefaultCPUDeviceMapper));

return registry;
}

DeviceMemoryManagerRegistryImpl* GetDeviceRegistry() {
DeviceMapperRegistryImpl* GetDeviceRegistry() {
static auto g_registry = CreateDeviceRegistry();
return g_registry.get();
}

} // namespace

Status RegisterDeviceMemoryManager(DeviceAllocationType device_type,
MemoryMapper memory_mapper) {
Status RegisterDeviceMapper(DeviceAllocationType device_type,
DeviceMapper mapper) {
auto registry = GetDeviceRegistry();
return registry->RegisterDevice(device_type, std::move(memory_mapper));
return registry->RegisterDevice(device_type, std::move(mapper));
}

Result<MemoryMapper> GetDeviceMemoryManager(DeviceAllocationType device_type) {
Result<DeviceMapper> GetDeviceMapper(DeviceAllocationType device_type) {
auto registry = GetDeviceRegistry();
return registry->GetMemoryManager(device_type);
return registry->GetMapper(device_type);
}

} // namespace arrow
7 changes: 3 additions & 4 deletions cpp/src/arrow/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ class ARROW_EXPORT CPUMemoryManager : public MemoryManager {
ARROW_EXPORT
std::shared_ptr<MemoryManager> default_cpu_memory_manager();

using MemoryMapper =
using DeviceMapper =
std::function<Result<std::shared_ptr<MemoryManager>>(int64_t device_id)>;

/// \brief Register a function to retrieve a MemoryManager for a Device type
Expand All @@ -380,8 +380,7 @@ using MemoryMapper =
/// MemoryManager for the registered device type and given device id
/// \return Status
ARROW_EXPORT
Status RegisterDeviceMemoryManager(DeviceAllocationType device_type,
MemoryMapper memory_mapper);
Status RegisterDeviceMapper(DeviceAllocationType device_type, DeviceMapper mapper);

/// \brief Get the registered function to retrieve a MemoryManager for the
/// given Device type
Expand All @@ -390,6 +389,6 @@ Status RegisterDeviceMemoryManager(DeviceAllocationType device_type,
/// \return function that takes a device id and returns the appropriate
/// MemoryManager for the registered device type and given device id
ARROW_EXPORT
Result<MemoryMapper> GetDeviceMemoryManager(DeviceAllocationType device_type);
Result<DeviceMapper> GetDeviceMapper(DeviceAllocationType device_type);

} // namespace arrow
5 changes: 2 additions & 3 deletions cpp/src/arrow/gpu/cuda_memory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -504,14 +504,13 @@ Result<std::shared_ptr<MemoryManager>> DefaultMemoryMapper(ArrowDeviceType devic

namespace {

Result<std::shared_ptr<MemoryManager>> DefaultCUDAMemoryMapper(int64_t device_id) {
Result<std::shared_ptr<MemoryManager>> DefaultCUDADeviceMapper(int64_t device_id) {
ARROW_ASSIGN_OR_RAISE(auto device, arrow::cuda::CudaDevice::Make(device_id));
return device->default_memory_manager();
}

bool RegisterCUDADeviceInternal() {
DCHECK_OK(
RegisterDeviceMemoryManager(DeviceAllocationType::kCUDA, DefaultCUDAMemoryMapper));
DCHECK_OK(RegisterDeviceMapper(DeviceAllocationType::kCUDA, DefaultCUDADeviceMapper));
// TODO add the CUDA_HOST and CUDA_MANAGED allocation types when they are supported in
// the CudaDevice
return true;
Expand Down

0 comments on commit a5a6f6c

Please sign in to comment.