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

feat: Add Meson support in nanoarrow_device #484

Merged
merged 8 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -202,4 +231,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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There also needs to be a compile define here -DNANOARROW_DEVICE_WITH_METAL (I think the error you were seeing might have happened even with this enabled if you don't have a Mac with a GPU; however, I'm seeing it also with the Meson build.

Also see #527 for a few updates to the metal build (+ adding it to CI).

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)
Loading