Skip to content
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

refactor: Consolidate per-target actions in CMakeLists.txt #573

Merged
204 changes: 115 additions & 89 deletions CMakeLists.txt

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion src/nanoarrow/device/cuda.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ struct ArrowDeviceCudaAllocatorPrivate {

static void ArrowDeviceCudaDeallocator(struct ArrowBufferAllocator* allocator,
uint8_t* ptr, int64_t old_size) {
NANOARROW_UNUSED(ptr);
NANOARROW_UNUSED(old_size);

struct ArrowDeviceCudaAllocatorPrivate* allocator_private =
(struct ArrowDeviceCudaAllocatorPrivate*)allocator->private_data;

Expand Down Expand Up @@ -515,7 +518,8 @@ static ArrowErrorCode ArrowDeviceCudaInitDevice(struct ArrowDevice* device,
}

CUdevice cu_device;
NANOARROW_CUDA_RETURN_NOT_OK(cuDeviceGet(&cu_device, device_id), "cuDeviceGet", error);
NANOARROW_CUDA_RETURN_NOT_OK(cuDeviceGet(&cu_device, (int)device_id), "cuDeviceGet",
error);

CUcontext cu_context;
NANOARROW_CUDA_RETURN_NOT_OK(cuDevicePrimaryCtxRetain(&cu_context, cu_device),
Expand Down
19 changes: 15 additions & 4 deletions src/nanoarrow/device/metal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@
#include <string.h>
#include <unistd.h>

#define NS_PRIVATE_IMPLEMENTATION
#define MTL_PRIVATE_IMPLEMENTATION
#include <Metal/Metal.hpp>

#include "nanoarrow/device/metal_impl.h"
#include "nanoarrow/nanoarrow_device.hpp"

// If non-null, caller must ->release() the return value. This doesn't
Expand Down Expand Up @@ -62,6 +59,8 @@ static MTL::Buffer* ArrowDeviceMetalWrapBufferNonOwning(MTL::Device* mtl_device,
static uint8_t* ArrowDeviceMetalAllocatorReallocate(
struct ArrowBufferAllocator* allocator, uint8_t* ptr, int64_t old_size,
int64_t new_size) {
NANOARROW_UNUSED(allocator);

// Cache the page size from the system call
static int pagesize = 0;
if (pagesize == 0) {
Expand Down Expand Up @@ -103,6 +102,8 @@ static uint8_t* ArrowDeviceMetalAllocatorReallocate(

static void ArrowDeviceMetalAllocatorFree(struct ArrowBufferAllocator* allocator,
uint8_t* ptr, int64_t old_size) {
NANOARROW_UNUSED(allocator);
NANOARROW_UNUSED(old_size);
free(ptr);
}

Expand Down Expand Up @@ -188,6 +189,10 @@ static ArrowErrorCode ArrowDeviceMetalBufferInitAsync(struct ArrowDevice* device
struct ArrowDevice* device_dst,
struct ArrowBuffer* dst,
void* stream) {
if (stream != nullptr) {
return ENOTSUP;
}

if (device_src->device_type == ARROW_DEVICE_CPU &&
device_dst->device_type == ARROW_DEVICE_METAL) {
struct ArrowBuffer tmp;
Expand Down Expand Up @@ -255,6 +260,10 @@ static ArrowErrorCode ArrowDeviceMetalBufferCopyAsync(struct ArrowDevice* device
struct ArrowDevice* device_dst,
struct ArrowBufferView dst,
void* stream) {
if (stream != nullptr) {
return ENOTSUP;
}

// This is all just memcpy since it's all living in the same address space
if (device_src->device_type == ARROW_DEVICE_CPU &&
device_dst->device_type == ARROW_DEVICE_METAL) {
Expand Down Expand Up @@ -299,6 +308,8 @@ static int ArrowDeviceMetalCopyRequiredCpuToMetal(MTL::Device* mtl_device,
static ArrowErrorCode ArrowDeviceMetalSynchronize(struct ArrowDevice* device,
void* sync_event, void* stream,
struct ArrowError* error) {
NANOARROW_UNUSED(device);
NANOARROW_UNUSED(error);
// TODO: sync events for Metal are harder than for CUDA
// https://developer.apple.com/documentation/metal/resource_synchronization/synchronizing_events_between_a_gpu_and_the_cpu?language=objc
// It would be much easier if sync_event were a command buffer
Expand Down
20 changes: 20 additions & 0 deletions src/nanoarrow/device/metal_impl.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

#define NS_PRIVATE_IMPLEMENTATION
#define MTL_PRIVATE_IMPLEMENTATION
#include "metal_impl.h"
24 changes: 24 additions & 0 deletions src/nanoarrow/device/metal_impl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

// We have no control over the Metal headers
#pragma GCC diagnostic ignored "-Wgnu-anonymous-struct"
#pragma GCC diagnostic ignored "-Wnested-anon-types"
#pragma GCC diagnostic ignored "-Wignored-qualifiers"
#pragma GCC diagnostic push
#include <Metal/Metal.hpp>
#pragma GCC diagnostic pop
3 changes: 3 additions & 0 deletions src/nanoarrow/ipc/decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ struct ArrowIpcDecoderPrivate {
};

ArrowErrorCode ArrowIpcCheckRuntime(struct ArrowError* error) {
// Avoids an unused warning when bundling the header into nanoarrow_ipc.c
NANOARROW_UNUSED(flatbuffers_end);

const char* nanoarrow_runtime_version = ArrowNanoarrowVersion();
const char* nanoarrow_ipc_build_time_version = NANOARROW_VERSION;

Expand Down
21 changes: 14 additions & 7 deletions src/nanoarrow/ipc/encoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,22 +218,26 @@ static ArrowErrorCode ArrowIpcEncodeFieldType(flatcc_builder_t* builder,

case NANOARROW_TYPE_TIMESTAMP:
FLATCC_RETURN_UNLESS_0(Field_type_Timestamp_start(builder));
FLATCC_RETURN_UNLESS_0(Timestamp_unit_add(builder, schema_view->time_unit));
FLATCC_RETURN_UNLESS_0(
Timestamp_unit_add(builder, (ns(TimeUnit_enum_t))schema_view->time_unit));
FLATCC_RETURN_UNLESS_0(
Timestamp_timezone_create_str(builder, schema_view->timezone));
FLATCC_RETURN_UNLESS_0(Field_type_Timestamp_end(builder));
return NANOARROW_OK;

case NANOARROW_TYPE_TIME32:
FLATCC_RETURN_UNLESS_0(Field_type_Time_create(builder, schema_view->time_unit, 32));
FLATCC_RETURN_UNLESS_0(Field_type_Time_create(
builder, (ns(TimeUnit_enum_t))schema_view->time_unit, 32));
return NANOARROW_OK;

case NANOARROW_TYPE_TIME64:
FLATCC_RETURN_UNLESS_0(Field_type_Time_create(builder, schema_view->time_unit, 64));
FLATCC_RETURN_UNLESS_0(Field_type_Time_create(
builder, (ns(TimeUnit_enum_t))schema_view->time_unit, 64));
return NANOARROW_OK;

case NANOARROW_TYPE_DURATION:
FLATCC_RETURN_UNLESS_0(Field_type_Duration_create(builder, schema_view->time_unit));
FLATCC_RETURN_UNLESS_0(Field_type_Duration_create(
builder, (ns(TimeUnit_enum_t))schema_view->time_unit));
return NANOARROW_OK;

case NANOARROW_TYPE_FIXED_SIZE_BINARY:
Expand Down Expand Up @@ -316,10 +320,12 @@ static ArrowErrorCode ArrowIpcEncodeMetadata(flatcc_builder_t* builder,
(*push_end)(flatcc_builder_t*),
struct ArrowError* error) {
struct ArrowMetadataReader metadata;
NANOARROW_RETURN_NOT_OK(ArrowMetadataReaderInit(&metadata, schema->metadata));
NANOARROW_RETURN_NOT_OK_WITH_ERROR(ArrowMetadataReaderInit(&metadata, schema->metadata),
error);
while (metadata.remaining_keys > 0) {
struct ArrowStringView key, value;
NANOARROW_RETURN_NOT_OK(ArrowMetadataReaderRead(&metadata, &key, &value));
NANOARROW_RETURN_NOT_OK_WITH_ERROR(ArrowMetadataReaderRead(&metadata, &key, &value),
error);
if (push_start(builder) != 0) {
return ENOMEM;
}
Expand Down Expand Up @@ -395,7 +401,8 @@ ArrowErrorCode ArrowIpcEncoderEncodeSchema(struct ArrowIpcEncoder* encoder,

FLATCC_RETURN_UNLESS_0(Message_header_Schema_start(builder));

FLATCC_RETURN_UNLESS_0(Schema_endianness_add(builder, ArrowIpcSystemEndianness()));
FLATCC_RETURN_UNLESS_0(
Schema_endianness_add(builder, (ns(Endianness_enum_t))ArrowIpcSystemEndianness()));

FLATCC_RETURN_UNLESS_0(Schema_fields_start(builder));
NANOARROW_RETURN_NOT_OK(ArrowIpcEncodeFields(builder, schema,
Expand Down
2 changes: 1 addition & 1 deletion src/nanoarrow/testing/testing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1564,7 +1564,7 @@ ArrowErrorCode SetBufferBitmap(const json& value, ArrowBitmap* bitmap,
// says [1, 0, 1]. Accept both for simplicity.
NANOARROW_RETURN_NOT_OK(Check(item.is_boolean() || item.is_number_integer(), error,
"bitmap item must be bool or integer"));
NANOARROW_RETURN_NOT_OK_WITH_ERROR(ArrowBitmapAppend(bitmap, item.get<int>(), 1),
NANOARROW_RETURN_NOT_OK_WITH_ERROR(ArrowBitmapAppend(bitmap, item.get<uint8_t>(), 1),
error);
}

Expand Down
Loading