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

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ members = [
"vortex-duckdb",
"vortex-cuda",
"vortex-cuda/cub",
"vortex-cuda/ffi",
"vortex-cuda/gpu-scan-cli",
"vortex-cuda/macros",
"vortex-cuda/nvcomp",
Expand Down
33 changes: 33 additions & 0 deletions vortex-cuda/ffi/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[package]
name = "vortex-cuda-ffi"
description = "Native C FFI bindings for Vortex CUDA interop"
readme = "README.md"
publish = false
version = { workspace = true }
homepage = { workspace = true }
repository = { workspace = true }
authors = { workspace = true }
license = { workspace = true }
keywords = { workspace = true }
include = { workspace = true }
edition = { workspace = true }
rust-version = { workspace = true }
categories = { workspace = true }

[dependencies]
arrow-schema = { workspace = true, features = ["ffi"] }
futures = { workspace = true, features = ["executor"] }
vortex = { workspace = true, features = ["object_store"] }
vortex-cuda = { path = ".." }
vortex-ffi = { path = "../../vortex-ffi" }

[dev-dependencies]
vortex-array = { workspace = true, features = ["_test-harness"] }
vortex-cuda-macros = { workspace = true }

[lib]
name = "vortex_cuda_ffi"
crate-type = ["rlib", "staticlib", "cdylib"]

[lints]
workspace = true
16 changes: 16 additions & 0 deletions vortex-cuda/ffi/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# vortex-cuda-ffi

CUDA-specific C FFI helpers for cuDF interop.

This crate keeps CUDA out of the base `vortex-ffi` crate. Its public C API exports a borrowed `vx_array` as an `ArrowSchema + ArrowDeviceArray` pair.

It does not create cuDF objects itself. The caller passes the exported Arrow Device structs to cuDF and releases them after cuDF is done importing.

Use this crate as the CUDA-enabled FFI artifact. Include both headers:

```c
#include "vortex.h"
#include "vortex_cuda.h"
```

and link the CUDA FFI library (`vortex_cuda_ffi`). Do not pass Vortex handles between independently linked Rust FFI libraries.
78 changes: 78 additions & 0 deletions vortex-cuda/ffi/cinclude/vortex_cuda.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright the Vortex contributors
#pragma once

#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. */

#ifdef __cplusplus
extern "C" {
#endif

#ifndef USE_OWN_ARROW_DEVICE
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

typedef struct vx_cuda_error vx_cuda_error;

/**
* Return the message for a CUDA FFI error.
*
* The returned pointer is valid until `error` is freed with `vx_cuda_error_free`.
*/
const char *vx_cuda_error_get_message(const vx_cuda_error *error);

/** Free a CUDA FFI error. */
void vx_cuda_error_free(vx_cuda_error *error);

/**
* Export a borrowed Vortex array for cuDF's Arrow Device import path.
*
* On success, returns 0 and writes independently releasable `out_schema` and `out_array` values.
* This function does not create a cuDF object; the caller passes these outputs to cuDF and releases
* both with their embedded Arrow callbacks after cuDF is done importing.
*
* Guarantees:
* - `out_array->device_type == ARROW_DEVICE_CUDA`.
* - `out_array->device_id` identifies the CUDA device for every exported buffer.
* - Struct arrays export as table-shaped schemas; non-struct arrays export as column fields.
* - Schema/layout remapping matches Vortex's CUDA exporter, including decimals and lists.
*
* On error, returns 1 and writes `error_out` when it is not NULL.
*/
int vx_cuda_array_export_arrow_device(const vx_session *session,
const vx_array *array,
FFI_ArrowSchema *out_schema,
struct ArrowDeviceArray *out_array,
vx_cuda_error **error_out);


#ifdef __cplusplus
}
#endif
Loading
Loading