Skip to content
Open
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
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions vortex-cuda/ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@ vortex-cuda = { path = ".." }
vortex-ffi = { path = "../../vortex-ffi" }

[dev-dependencies]
tempfile = { workspace = true }
vortex-cuda-macros = { workspace = true }

[build-dependencies]
cbindgen = { workspace = true }

[lib]
name = "vortex_cuda_ffi"
crate-type = ["rlib", "staticlib", "cdylib"]
Expand Down
5 changes: 5 additions & 0 deletions vortex-cuda/ffi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,8 @@ pool and CUDA state are reused as well.
On Linux, use `vx_cuda_scan_path_arrow_device_stream_with_options` with
`vx_cuda_scan_options.flags = VX_CUDA_SCAN_FLAG_DIRECT_IO` to bypass the operating system page
cache for pooled data-plane reads. Footer and zone-map reads remain buffered on the host.

`build.rs` generates `cinclude/vortex_cuda.h` with cbindgen on stable Rust, without macro
expansion. Edit the API and docs in `src/lib.rs`, not the generated header; commit
regenerated headers with API changes. `cbindgen.toml` supplies the standard Arrow Device
interface compatibility preamble.
29 changes: 29 additions & 0 deletions vortex-cuda/ffi/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright the Vortex contributors

use std::error::Error;
use std::process::Command;

fn main() -> Result<(), Box<dyn Error>> {
println!("cargo:rerun-if-changed=src");
println!("cargo:rerun-if-changed=cbindgen.toml");
println!("cargo:rerun-if-changed=build.rs");

let header = "cinclude/vortex_cuda.h";
// The CUDA API needs no macro expansion or dependency parsing, so generate on stable Rust
// without recursively building the CUDA implementation.
cbindgen::Builder::new()
.with_src("src/lib.rs")
.with_config(cbindgen::Config::from_file("cbindgen.toml")?)
.generate()?
.write_to_file(header);
if !Command::new("clang-format")
.args(["--style=file", "-i"])
.arg(header)
.status()
.is_ok_and(|status| status.success())
{
println!("cargo:warning=clang-format unavailable or failed; CUDA header left unformatted");
}
Ok(())
}
72 changes: 72 additions & 0 deletions vortex-cuda/ffi/cbindgen.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright the Vortex contributors

language = "C"
braces = "SameLine"
cpp_compat = true
usize_is_size_t = true
style = "both"
no_includes = true

header = """
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright the Vortex contributors
#pragma once

// THIS FILE IS AUTO-GENERATED, DO NOT MAKE EDITS DIRECTLY

#include <stddef.h>
#include <stdint.h>

#include "vortex.h"

/* Link against the CUDA-enabled FFI library that provides both the base Vortex FFI and these CUDA
* entry points. Do not pass Vortex handles between independently linked Rust FFI libraries. */

/* Definitions from the Arrow C Device data interface. Define USE_OWN_ARROW_DEVICE to skip them.
* https://arrow.apache.org/docs/format/CDeviceDataInterface.html */
#if !defined(ARROW_C_DEVICE_DATA_INTERFACE) && !defined(USE_OWN_ARROW_DEVICE)
#define ARROW_C_DEVICE_DATA_INTERFACE

typedef int32_t ArrowDeviceType;
#define ARROW_DEVICE_CPU 1
#define ARROW_DEVICE_CUDA 2
#define ARROW_DEVICE_CUDA_HOST 3
#define ARROW_DEVICE_OPENCL 4
#define ARROW_DEVICE_VULKAN 7
#define ARROW_DEVICE_METAL 8
#define ARROW_DEVICE_VPI 9
#define ARROW_DEVICE_ROCM 10
#define ARROW_DEVICE_ROCM_HOST 11
#define ARROW_DEVICE_EXT_DEV 12
#define ARROW_DEVICE_CUDA_MANAGED 13
#define ARROW_DEVICE_ONEAPI 14
#define ARROW_DEVICE_WEBGPU 15
#define ARROW_DEVICE_HEXAGON 16

struct ArrowDeviceArray {
struct ArrowArray array;
int64_t device_id;
ArrowDeviceType device_type;
void *sync_event;
int64_t reserved[3];
};
#endif

#if !defined(ARROW_C_DEVICE_STREAM_INTERFACE) && !defined(USE_OWN_ARROW_DEVICE)
#define ARROW_C_DEVICE_STREAM_INTERFACE
struct ArrowDeviceArrayStream {
ArrowDeviceType device_type;
int (*get_schema)(struct ArrowDeviceArrayStream *, struct ArrowSchema *out);
int (*get_next)(struct ArrowDeviceArrayStream *, struct ArrowDeviceArray *out);
const char *(*get_last_error)(struct ArrowDeviceArrayStream *);
void (*release)(struct ArrowDeviceArrayStream *);
void *private_data;
};
#endif
"""

# These externally defined Arrow ABI types use struct tags, not typedef names.
[export.rename]
"ArrowDeviceArray" = "struct ArrowDeviceArray"
"ArrowDeviceArrayStream" = "struct ArrowDeviceArrayStream"
Loading
Loading