From 9c4c7eca13bc828ec2401848a6ee7577d65bcaef Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Tue, 11 Jun 2024 16:52:40 -0400 Subject: [PATCH 1/6] feat: Meson build system for device --- meson.options | 4 +++ src/nanoarrow/meson.build | 56 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/meson.options b/meson.options index b91509820..3e9f60fba 100644 --- a/meson.options +++ b/meson.options @@ -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) diff --git a/src/nanoarrow/meson.build b/src/nanoarrow/meson.build index ccf59c990..319289cae 100644 --- a/src/nanoarrow/meson.build +++ b/src/nanoarrow/meson.build @@ -84,6 +84,29 @@ 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] + + if get_option('metal') + metal_dep = dependency('appleframeworks', modules: ['Foundation', 'Quartz', 'Metal']) + device_deps += metal_dep + endif + + if get_option('cuda') + cuda_dep = dependency('cuda', modules: ['cublas']) + device_deps += cuda_dep + endif + + nanoarrow_device_lib = build_target( + 'nanoarrow_device', + 'nanoarrow_device.c', + dependencies: device_deps, + install: true, + target_type: libtype, + ) +endif + if get_option('tests') or get_option('integration_tests') nlohmann_json_dep = dependency('nlohmann_json') @@ -199,4 +222,37 @@ if get_option('tests') test(name, exc) 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_dep], + ) + test('nanoarrow-device-metal', exc) + endif + + if get_option('cuda') + exc = executable( + 'nanoarrow-device-cuda-test', + 'nanoarrow_device_cuda_test.cc', + link_with: nanoarrow_device_lib, + dependencies: [nanoarrow_dep, gtest_dep, cuda_dep], + ) + test('nanoarrow-device-cuda', exc) + endif + endif endif From 5f09083247be81c388c2d4844007d6ccadf1e4f9 Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Tue, 11 Jun 2024 16:57:06 -0400 Subject: [PATCH 2/6] Add compile options to script --- ci/scripts/build-with-meson.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/scripts/build-with-meson.sh b/ci/scripts/build-with-meson.sh index cd76c6db8..617903c03 100755 --- a/ci/scripts/build-with-meson.sh +++ b/ci/scripts/build-with-meson.sh @@ -66,7 +66,7 @@ function main() { pushd "${SANDBOX_DIR}" show_header "Run test suite" - meson configure -Dtests=true -Db_coverage=true + meson configure -Dtests=true -Db_coverage=true -Dipc=true -Ddevice=true meson compile meson test --wrap='valgrind --track-origins=yes --leak-check=full' --print-errorlogs From 4d9eb55682510a7c9f751a6f778205d276008fa2 Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Thu, 13 Jun 2024 13:50:10 -0400 Subject: [PATCH 3/6] Metal support --- src/nanoarrow/meson.build | 13 +++++++--- src/nanoarrow/nanoarrow_device_metal.cc | 5 ++-- subprojects/metal-cpp.wrap | 26 +++++++++++++++++++ .../packagefiles/metal-cpp/meson.build | 4 +++ 4 files changed, 42 insertions(+), 6 deletions(-) create mode 100644 subprojects/metal-cpp.wrap create mode 100644 subprojects/packagefiles/metal-cpp/meson.build diff --git a/src/nanoarrow/meson.build b/src/nanoarrow/meson.build index 13c6ce557..059078139 100644 --- a/src/nanoarrow/meson.build +++ b/src/nanoarrow/meson.build @@ -83,20 +83,25 @@ 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'] if get_option('metal') - metal_dep = dependency('appleframeworks', modules: ['Foundation', 'Quartz', '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' endif if get_option('cuda') cuda_dep = dependency('cuda', modules: ['cublas']) device_deps += cuda_dep + device_srcs += 'nanoarrow_device_cuda.cc' endif nanoarrow_device_lib = build_target( 'nanoarrow_device', - 'nanoarrow_device.c', + sources: device_srcs, dependencies: device_deps, install: true, target_type: libtype, @@ -123,7 +128,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') @@ -243,7 +248,7 @@ if get_option('tests') 'nanoarrow-device-metal-test', 'nanoarrow_device_metal_test.cc', link_with: nanoarrow_device_lib, - dependencies: [nanoarrow_dep, gtest_dep, metal_dep], + dependencies: [nanoarrow_dep, gtest_dep, metal_cpp_dep], ) test('nanoarrow-device-metal', exc) endif diff --git a/src/nanoarrow/nanoarrow_device_metal.cc b/src/nanoarrow/nanoarrow_device_metal.cc index 43f064898..0db18f2c0 100644 --- a/src/nanoarrow/nanoarrow_device_metal.cc +++ b/src/nanoarrow/nanoarrow_device_metal.cc @@ -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(sync_event); memset(device_array, 0, sizeof(struct ArrowDeviceArray)); device_array->array = *array; @@ -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 && diff --git a/subprojects/metal-cpp.wrap b/subprojects/metal-cpp.wrap new file mode 100644 index 000000000..aa85e3ebf --- /dev/null +++ b/subprojects/metal-cpp.wrap @@ -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 diff --git a/subprojects/packagefiles/metal-cpp/meson.build b/subprojects/packagefiles/metal-cpp/meson.build new file mode 100644 index 000000000..1a7e1a003 --- /dev/null +++ b/subprojects/packagefiles/metal-cpp/meson.build @@ -0,0 +1,4 @@ +project('metal-cpp', 'cpp') + +incdir = include_directories('.') +metal_cpp_dep = declare_dependency(include_directories: incdir) From a420705829f303470427954ec64996ff37c22e09 Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Thu, 13 Jun 2024 14:18:06 -0400 Subject: [PATCH 4/6] license fix --- .../packagefiles/metal-cpp/meson.build | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/subprojects/packagefiles/metal-cpp/meson.build b/subprojects/packagefiles/metal-cpp/meson.build index 1a7e1a003..ba3beb405 100644 --- a/subprojects/packagefiles/metal-cpp/meson.build +++ b/subprojects/packagefiles/metal-cpp/meson.build @@ -1,4 +1,25 @@ -project('metal-cpp', 'cpp') +# 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) From 0fa48e863e68441f5dc52f5d4cf5d48d48ba3b7a Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Thu, 13 Jun 2024 14:29:39 -0400 Subject: [PATCH 5/6] try cuda_driver module --- src/nanoarrow/meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nanoarrow/meson.build b/src/nanoarrow/meson.build index 059078139..df43af0b3 100644 --- a/src/nanoarrow/meson.build +++ b/src/nanoarrow/meson.build @@ -94,7 +94,7 @@ if needs_device endif if get_option('cuda') - cuda_dep = dependency('cuda', modules: ['cublas']) + cuda_dep = dependency('cuda', modules: ['cuda_driver']) device_deps += cuda_dep device_srcs += 'nanoarrow_device_cuda.cc' endif From 3470c71dadb46e7b91039925c0d35f20c6552609 Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Sat, 15 Jun 2024 22:41:18 -0400 Subject: [PATCH 6/6] Metal / CUDA feedback --- src/nanoarrow/meson.build | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/src/nanoarrow/meson.build b/src/nanoarrow/meson.build index df43af0b3..2662e312c 100644 --- a/src/nanoarrow/meson.build +++ b/src/nanoarrow/meson.build @@ -84,6 +84,7 @@ 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']) @@ -91,12 +92,11 @@ if needs_device 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') - cuda_dep = dependency('cuda', modules: ['cuda_driver']) - device_deps += cuda_dep - device_srcs += 'nanoarrow_device_cuda.cc' + error('CUDA support with the Meson build system is not implemented') endif nanoarrow_device_lib = build_target( @@ -105,6 +105,7 @@ if needs_device dependencies: device_deps, install: true, target_type: libtype, + cpp_args: device_defines, ) endif @@ -252,15 +253,5 @@ if get_option('tests') ) test('nanoarrow-device-metal', exc) endif - - if get_option('cuda') - exc = executable( - 'nanoarrow-device-cuda-test', - 'nanoarrow_device_cuda_test.cc', - link_with: nanoarrow_device_lib, - dependencies: [nanoarrow_dep, gtest_dep, cuda_dep], - ) - test('nanoarrow-device-cuda', exc) - endif endif endif