Skip to content

Commit

Permalink
feat: Add Meson support in nanoarrow_device (#484)
Browse files Browse the repository at this point in the history
Co-authored-by: Will Ayd <willayd@Alisons-MBP.hsd1.md.comcast.net>
  • Loading branch information
WillAyd and Will Ayd authored Jun 17, 2024
1 parent 397cfc5 commit 1febb81
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 3 deletions.
5 changes: 5 additions & 0 deletions ci/scripts/build-with-meson.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,10 @@ function main() {
-Db_sanitize="address,undefined" \
-Dtests=true \
-Dipc=true \
-Ddevice=true \
-Dbenchmarks=false \
-Db_coverage=false

meson compile
export ASAN_OPTIONS=allocator_may_return_null=1 # allow ENOMEM tests
meson test --print-errorlogs
Expand All @@ -83,6 +85,7 @@ function main() {
-Db_sanitize=none \
-Dtests=true \
-Dipc=true \
-Ddevice=true \
-Dbenchmarks=false \
-Db_coverage=false
meson compile
Expand All @@ -94,6 +97,7 @@ function main() {
-Db_sanitize=none \
-Dtests=false \
-Dipc=true \
-Ddevice=true \
-Dbenchmarks=true \
-Db_coverage=false
meson compile
Expand All @@ -105,6 +109,7 @@ function main() {
-Db_sanitize=none \
-Dtests=true \
-Dipc=true \
-Ddevice=true \
-Dbenchmarks=false \
-Db_coverage=true

Expand Down
4 changes: 4 additions & 0 deletions meson.options
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@ option('integration_tests', type: 'boolean',
value: false)
option('namespace', type: 'string',
description: 'A prefix for exported symbols')
option('device', type: 'boolean', description: 'Build device libraries', value: false)
option('metal', type: 'boolean', description: 'Build Apple metal libraries',
value: false)
option('cuda', type: 'boolean', description: 'Build CUDA libraries', value: false)
54 changes: 53 additions & 1 deletion src/nanoarrow/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,35 @@ if get_option('ipc')
dependencies: [nanoarrow_dep, flatcc_dep])
endif

needs_device = get_option('device') or get_option('metal') or get_option('cuda')
if needs_device
device_deps = [nanoarrow_dep]
device_srcs = ['nanoarrow_device.c']
device_defines = []

if get_option('metal')
metal_dep = dependency('appleframeworks', modules: ['Foundation', 'Metal'])
metal_cpp_dep = dependency('metal-cpp')
device_deps += metal_dep
device_deps += metal_cpp_dep
device_srcs += 'nanoarrow_device_metal.cc'
device_defines += '-DNANOARROW_DEVICE_WITH_METAL'
endif

if get_option('cuda')
error('CUDA support with the Meson build system is not implemented')
endif

nanoarrow_device_lib = build_target(
'nanoarrow_device',
sources: device_srcs,
dependencies: device_deps,
install: true,
target_type: libtype,
cpp_args: device_defines,
)
endif

if get_option('tests') or get_option('integration_tests')
nlohmann_json_dep = dependency('nlohmann_json')

Expand All @@ -100,7 +129,7 @@ if get_option('tests')
# https://mesonbuild.com/Unit-tests.html#coverage

arrow_dep = dependency('arrow')
gtest_dep = dependency('gtest', fallback: ['gtest', 'gtest_main_dep'])
gtest_dep = dependency('gtest_main')
gmock_dep = dependency('gmock')
nlohmann_json_dep = dependency('nlohmann_json')

Expand Down Expand Up @@ -185,4 +214,27 @@ if get_option('tests')
test(name, exc, timeout: config['timeout'])
endforeach
endif

if needs_device
device_tests = ['nanoarrow_device', 'nanoarrow_device_hpp']
foreach device_test : device_tests
exc = executable(
device_test.replace('_', '-') + '-test',
device_test + '_test.cc',
link_with: nanoarrow_device_lib,
dependencies: [nanoarrow_dep, gtest_dep],
)
test(device_test.replace('_', '-'), exc)
endforeach

if get_option('metal')
exc = executable(
'nanoarrow-device-metal-test',
'nanoarrow_device_metal_test.cc',
link_with: nanoarrow_device_lib,
dependencies: [nanoarrow_dep, gtest_dep, metal_cpp_dep],
)
test('nanoarrow-device-metal', exc)
endif
endif
endif
5 changes: 3 additions & 2 deletions src/nanoarrow/nanoarrow_device_metal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ static ArrowErrorCode ArrowDeviceMetalArrayInit(struct ArrowDevice* device,
}

// One can create a new event with mtl_device->newSharedEvent();
private_data->event = sync_event;
private_data->event = static_cast<MTL::SharedEvent*>(sync_event);

memset(device_array, 0, sizeof(struct ArrowDeviceArray));
device_array->array = *array;
Expand Down Expand Up @@ -330,7 +330,8 @@ static ArrowErrorCode ArrowDeviceMetalArrayMove(struct ArrowDevice* device_src,
return ENOTSUP;
}

NANOARROW_RETURN_NOT_OK(ArrowDeviceArrayInit(device_dst, dst, &src->array));
NANOARROW_RETURN_NOT_OK(
ArrowDeviceArrayInit(device_dst, dst, &src->array, src->sync_event));
return NANOARROW_OK;

} else if (device_src->device_type == ARROW_DEVICE_METAL &&
Expand Down
26 changes: 26 additions & 0 deletions subprojects/metal-cpp.wrap
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# 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.

[wrap-file]
directory = metal-cpp
source_url = https://developer.apple.com/metal/cpp/files/metal-cpp_macOS12_iOS15.zip
source_filename = metal-cpp_macOS12_iOS15.zip
source_hash = a4e2d4668951b6f2595618ed8c5dc514fc94fda5487fc722b1c1ff29d7b524f7
patch_directory = metal-cpp

[provide]
metal-cpp = metal_cpp_dep
25 changes: 25 additions & 0 deletions subprojects/packagefiles/metal-cpp/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# 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.

project(
'metal-cpp',
'cpp',
license : 'Apache-2.0',
)

incdir = include_directories('.')
metal_cpp_dep = declare_dependency(include_directories: incdir)

0 comments on commit 1febb81

Please sign in to comment.