mirror of
https://github.com/apache/arrow.git
synced 2026-10-29 00:56:31 +08:00
[GLib] Rename libarrow-gpu-glib to libarrow-cuda-glib
This commit is contained in:
1 parent
9687346aca
commit
267de1b87c
27 files changed
+1425
-1426
No files matched your search
+1
-1
@@ -51,12 +51,12 @@ Makefile.in
|
||||
/libtool
|
||||
/m4/
|
||||
/stamp-h1
|
||||
/arrow-cuda-glib/*.pc
|
||||
/arrow-glib/enums.c
|
||||
/arrow-glib/enums.h
|
||||
/arrow-glib/stamp-*
|
||||
/arrow-glib/version.h
|
||||
/arrow-glib/*.pc
|
||||
/arrow-gpu-glib/*.pc
|
||||
/gandiva-glib/*.pc
|
||||
/parquet-glib/*.pc
|
||||
/plasma-glib/*.pc
|
||||
|
||||
+1
-1
@@ -19,7 +19,7 @@ ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS}
|
||||
|
||||
SUBDIRS = \
|
||||
arrow-glib \
|
||||
arrow-gpu-glib \
|
||||
arrow-cuda-glib \
|
||||
gandiva-glib \
|
||||
parquet-glib \
|
||||
plasma-glib \
|
||||
|
||||
@@ -24,51 +24,51 @@ AM_CPPFLAGS = \
|
||||
-I$(top_builddir) \
|
||||
-I$(top_srcdir)
|
||||
|
||||
if HAVE_ARROW_GPU
|
||||
if HAVE_ARROW_CUDA
|
||||
lib_LTLIBRARIES = \
|
||||
libarrow-gpu-glib.la
|
||||
libarrow-cuda-glib.la
|
||||
|
||||
libarrow_gpu_glib_la_CXXFLAGS = \
|
||||
libarrow_cuda_glib_la_CXXFLAGS = \
|
||||
$(GLIB_CFLAGS) \
|
||||
$(ARROW_CFLAGS) \
|
||||
$(ARROW_GPU_CFLAGS) \
|
||||
$(ARROW_CUDA_CFLAGS) \
|
||||
$(GARROW_CXXFLAGS)
|
||||
|
||||
libarrow_gpu_glib_la_LDFLAGS = \
|
||||
libarrow_cuda_glib_la_LDFLAGS = \
|
||||
-version-info $(LT_VERSION_INFO) \
|
||||
-no-undefined
|
||||
|
||||
libarrow_gpu_glib_la_LIBADD = \
|
||||
libarrow_cuda_glib_la_LIBADD = \
|
||||
$(GLIB_LIBS) \
|
||||
$(ARROW_LIBS) \
|
||||
$(ARROW_GPU_LIBS) \
|
||||
$(ARROW_CUDA_LIBS) \
|
||||
../arrow-glib/libarrow-glib.la
|
||||
|
||||
libarrow_gpu_glib_la_headers = \
|
||||
arrow-gpu-glib.h \
|
||||
libarrow_cuda_glib_la_headers = \
|
||||
arrow-cuda-glib.h \
|
||||
cuda.h
|
||||
|
||||
libarrow_gpu_glib_la_sources = \
|
||||
libarrow_cuda_glib_la_sources = \
|
||||
cuda.cpp \
|
||||
$(libarrow_gpu_glib_la_headers)
|
||||
$(libarrow_cuda_glib_la_headers)
|
||||
|
||||
libarrow_gpu_glib_la_cpp_headers = \
|
||||
arrow-gpu-glib.hpp \
|
||||
libarrow_cuda_glib_la_cpp_headers = \
|
||||
arrow-cuda-glib.hpp \
|
||||
cuda.hpp
|
||||
|
||||
libarrow_gpu_glib_la_SOURCES = \
|
||||
$(libarrow_gpu_glib_la_sources) \
|
||||
$(libarrow_gpu_glib_la_cpp_headers)
|
||||
libarrow_cuda_glib_la_SOURCES = \
|
||||
$(libarrow_cuda_glib_la_sources) \
|
||||
$(libarrow_cuda_glib_la_cpp_headers)
|
||||
|
||||
arrow_gpu_glib_includedir = \
|
||||
$(includedir)/arrow-gpu-glib
|
||||
arrow_gpu_glib_include_HEADERS = \
|
||||
$(libarrow_gpu_glib_la_headers) \
|
||||
$(libarrow_gpu_glib_la_cpp_headers)
|
||||
arrow_cuda_glib_includedir = \
|
||||
$(includedir)/arrow-cuda-glib
|
||||
arrow_cuda_glib_include_HEADERS = \
|
||||
$(libarrow_cuda_glib_la_headers) \
|
||||
$(libarrow_cuda_glib_la_cpp_headers)
|
||||
|
||||
pkgconfigdir = $(libdir)/pkgconfig
|
||||
pkgconfig_DATA = \
|
||||
arrow-gpu-glib.pc
|
||||
arrow-cuda-glib.pc
|
||||
|
||||
if HAVE_INTROSPECTION
|
||||
-include $(INTROSPECTION_MAKEFILE)
|
||||
@@ -85,39 +85,39 @@ endif
|
||||
INTROSPECTION_COMPILER_ARGS = \
|
||||
--includedir=$(abs_builddir)/../arrow-glib
|
||||
|
||||
ArrowGPU-1.0.gir: libarrow-gpu-glib.la
|
||||
ArrowGPU_1_0_gir_PACKAGES = \
|
||||
ArrowCUDA-1.0.gir: libarrow-cuda-glib.la
|
||||
ArrowCUDA_1_0_gir_PACKAGES = \
|
||||
arrow-glib
|
||||
ArrowGPU_1_0_gir_EXPORT_PACKAGES = \
|
||||
arrow-gpu-glib
|
||||
ArrowGPU_1_0_gir_INCLUDES = \
|
||||
ArrowCUDA_1_0_gir_EXPORT_PACKAGES = \
|
||||
arrow-cuda-glib
|
||||
ArrowCUDA_1_0_gir_INCLUDES = \
|
||||
Arrow-1.0
|
||||
ArrowGPU_1_0_gir_CFLAGS = \
|
||||
ArrowCUDA_1_0_gir_CFLAGS = \
|
||||
$(AM_CPPFLAGS)
|
||||
ArrowGPU_1_0_gir_LIBS =
|
||||
ArrowGPU_1_0_gir_FILES = \
|
||||
$(libarrow_gpu_glib_la_sources)
|
||||
ArrowGPU_1_0_gir_SCANNERFLAGS = \
|
||||
ArrowCUDA_1_0_gir_LIBS =
|
||||
ArrowCUDA_1_0_gir_FILES = \
|
||||
$(libarrow_cuda_glib_la_sources)
|
||||
ArrowCUDA_1_0_gir_SCANNERFLAGS = \
|
||||
--library-path=$(ARROW_LIB_DIR) \
|
||||
--warn-all \
|
||||
--add-include-path=$(abs_builddir)/../arrow-glib \
|
||||
--identifier-prefix=GArrowGPU \
|
||||
--symbol-prefix=garrow_gpu
|
||||
--identifier-prefix=GArrowCUDA \
|
||||
--symbol-prefix=garrow_cuda
|
||||
if OS_MACOS
|
||||
ArrowGPU_1_0_gir_LIBS += \
|
||||
ArrowCUDA_1_0_gir_LIBS += \
|
||||
arrow-glib \
|
||||
arrow-gpu-glib
|
||||
ArrowGPU_1_0_gir_SCANNERFLAGS += \
|
||||
arrow-cuda-glib
|
||||
ArrowCUDA_1_0_gir_SCANNERFLAGS += \
|
||||
--no-libtool \
|
||||
--library-path=$(abs_builddir)/../arrow-glib/.libs \
|
||||
--library-path=$(abs_builddir)/.libs
|
||||
else
|
||||
ArrowGPU_1_0_gir_LIBS += \
|
||||
ArrowCUDA_1_0_gir_LIBS += \
|
||||
$(abs_builddir)/../arrow-glib/libarrow-glib.la \
|
||||
libarrow-gpu-glib.la
|
||||
libarrow-cuda-glib.la
|
||||
endif
|
||||
|
||||
INTROSPECTION_GIRS += ArrowGPU-1.0.gir
|
||||
INTROSPECTION_GIRS += ArrowCUDA-1.0.gir
|
||||
|
||||
girdir = $(datadir)/gir-1.0
|
||||
gir_DATA = $(INTROSPECTION_GIRS)
|
||||
@@ -21,4 +21,4 @@
|
||||
|
||||
#include <arrow-glib/arrow-glib.h>
|
||||
|
||||
#include <arrow-gpu-glib/cuda.h>
|
||||
#include <arrow-cuda-glib/cuda.h>
|
||||
+1
-1
@@ -21,4 +21,4 @@
|
||||
|
||||
#include <arrow-glib/arrow-glib.hpp>
|
||||
|
||||
#include <arrow-gpu-glib/cuda.hpp>
|
||||
#include <arrow-cuda-glib/cuda.hpp>
|
||||
+4
-4
@@ -20,9 +20,9 @@ exec_prefix=@exec_prefix@
|
||||
libdir=@libdir@
|
||||
includedir=@includedir@
|
||||
|
||||
Name: Apache Arrow GPU GLib
|
||||
Description: C API for Apache Arrow GPU based on GLib
|
||||
Name: Apache Arrow CUDA GLib
|
||||
Description: C API for Apache Arrow CUDA based on GLib
|
||||
Version: @VERSION@
|
||||
Libs: -L${libdir} -larrow-gpu-glib
|
||||
Libs: -L${libdir} -larrow-cuda-glib
|
||||
Cflags: -I${includedir}
|
||||
Requires: arrow-glib
|
||||
Requires: arrow-glib arrow-cuda
|
||||
@@ -0,0 +1,942 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <arrow-glib/buffer.hpp>
|
||||
#include <arrow-glib/error.hpp>
|
||||
#include <arrow-glib/input-stream.hpp>
|
||||
#include <arrow-glib/output-stream.hpp>
|
||||
#include <arrow-glib/readable.hpp>
|
||||
#include <arrow-glib/record-batch.hpp>
|
||||
#include <arrow-glib/schema.hpp>
|
||||
|
||||
#include <arrow-cuda-glib/cuda.hpp>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/**
|
||||
* SECTION: cuda
|
||||
* @section_id: cuda-classes
|
||||
* @title: CUDA related classes
|
||||
* @include: arrow-cuda-glib/arrow-cuda-glib.h
|
||||
*
|
||||
* The following classes provide CUDA support for Apache Arrow data.
|
||||
*
|
||||
* #GArrowCUDADeviceManager is the starting point. You need at
|
||||
* least one #GArrowCUDAContext to process Apache Arrow data on
|
||||
* NVIDIA GPU.
|
||||
*
|
||||
* #GArrowCUDAContext is a class to keep context for one GPU. You
|
||||
* need to create #GArrowCUDAContext for each GPU that you want to
|
||||
* use. You can create #GArrowCUDAContext by
|
||||
* garrow_cuda_device_manager_get_context().
|
||||
*
|
||||
* #GArrowCUDABuffer is a class for data on GPU. You can copy data
|
||||
* on GPU to/from CPU by garrow_cuda_buffer_copy_to_host() and
|
||||
* garrow_cuda_buffer_copy_from_host(). You can share data on GPU
|
||||
* with other processes by garrow_cuda_buffer_export() and
|
||||
* garrow_cuda_buffer_new_ipc().
|
||||
*
|
||||
* #GArrowCUDAHostBuffer is a class for data on CPU that is
|
||||
* directly accessible from GPU.
|
||||
*
|
||||
* #GArrowCUDAIPCMemoryHandle is a class to share data on GPU with
|
||||
* other processes. You can export your data on GPU to other processes
|
||||
* by garrow_cuda_buffer_export() and
|
||||
* garrow_cuda_ipc_memory_handle_new(). You can import other
|
||||
* process data on GPU by garrow_cuda_ipc_memory_handle_new() and
|
||||
* garrow_cuda_buffer_new_ipc().
|
||||
*
|
||||
* #GArrowCUDABufferInputStream is a class to read data in
|
||||
* #GArrowCUDABuffer.
|
||||
*
|
||||
* #GArrowCUDABufferOutputStream is a class to write data into
|
||||
* #GArrowCUDABuffer.
|
||||
*/
|
||||
|
||||
G_DEFINE_TYPE(GArrowCUDADeviceManager,
|
||||
garrow_cuda_device_manager,
|
||||
G_TYPE_OBJECT)
|
||||
|
||||
static void
|
||||
garrow_cuda_device_manager_init(GArrowCUDADeviceManager *object)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
garrow_cuda_device_manager_class_init(GArrowCUDADeviceManagerClass *klass)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* garrow_cuda_device_manager_new:
|
||||
* @error: (nullable): Return location for a #GError or %NULL.
|
||||
*
|
||||
* Returns: A newly created #GArrowCUDADeviceManager on success,
|
||||
* %NULL on error.
|
||||
*
|
||||
* Since: 0.8.0
|
||||
*/
|
||||
GArrowCUDADeviceManager *
|
||||
garrow_cuda_device_manager_new(GError **error)
|
||||
{
|
||||
arrow::cuda::CudaDeviceManager *manager;
|
||||
auto status = arrow::cuda::CudaDeviceManager::GetInstance(&manager);
|
||||
if (garrow_error_check(error, status, "[cuda][device-manager][new]")) {
|
||||
auto manager = g_object_new(GARROW_CUDA_TYPE_DEVICE_MANAGER,
|
||||
NULL);
|
||||
return GARROW_CUDA_DEVICE_MANAGER(manager);
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* garrow_cuda_device_manager_get_context:
|
||||
* @manager: A #GArrowCUDADeviceManager.
|
||||
* @gpu_number: A GPU device number for the target context.
|
||||
* @error: (nullable): Return location for a #GError or %NULL.
|
||||
*
|
||||
* Returns: (transfer full): A newly created #GArrowCUDAContext on
|
||||
* success, %NULL on error. Contexts for the same GPU device number
|
||||
* share the same data internally.
|
||||
*
|
||||
* Since: 0.8.0
|
||||
*/
|
||||
GArrowCUDAContext *
|
||||
garrow_cuda_device_manager_get_context(GArrowCUDADeviceManager *manager,
|
||||
gint gpu_number,
|
||||
GError **error)
|
||||
{
|
||||
arrow::cuda::CudaDeviceManager *arrow_manager;
|
||||
arrow::cuda::CudaDeviceManager::GetInstance(&arrow_manager);
|
||||
std::shared_ptr<arrow::cuda::CudaContext> context;
|
||||
auto status = arrow_manager->GetContext(gpu_number, &context);
|
||||
if (garrow_error_check(error, status,
|
||||
"[cuda][device-manager][get-context]]")) {
|
||||
return garrow_cuda_context_new_raw(&context);
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* garrow_cuda_device_manager_get_n_devices:
|
||||
* @manager: A #GArrowCUDADeviceManager.
|
||||
*
|
||||
* Returns: The number of GPU devices.
|
||||
*
|
||||
* Since: 0.8.0
|
||||
*/
|
||||
gsize
|
||||
garrow_cuda_device_manager_get_n_devices(GArrowCUDADeviceManager *manager)
|
||||
{
|
||||
arrow::cuda::CudaDeviceManager *arrow_manager;
|
||||
arrow::cuda::CudaDeviceManager::GetInstance(&arrow_manager);
|
||||
return arrow_manager->num_devices();
|
||||
}
|
||||
|
||||
|
||||
typedef struct GArrowCUDAContextPrivate_ {
|
||||
std::shared_ptr<arrow::cuda::CudaContext> context;
|
||||
} GArrowCUDAContextPrivate;
|
||||
|
||||
enum {
|
||||
PROP_CONTEXT = 1
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE_WITH_PRIVATE(GArrowCUDAContext,
|
||||
garrow_cuda_context,
|
||||
G_TYPE_OBJECT)
|
||||
|
||||
#define GARROW_CUDA_CONTEXT_GET_PRIVATE(object) \
|
||||
static_cast<GArrowCUDAContextPrivate *>( \
|
||||
garrow_cuda_context_get_instance_private( \
|
||||
GARROW_CUDA_CONTEXT(object)))
|
||||
|
||||
static void
|
||||
garrow_cuda_context_finalize(GObject *object)
|
||||
{
|
||||
auto priv = GARROW_CUDA_CONTEXT_GET_PRIVATE(object);
|
||||
|
||||
priv->context = nullptr;
|
||||
|
||||
G_OBJECT_CLASS(garrow_cuda_context_parent_class)->finalize(object);
|
||||
}
|
||||
|
||||
static void
|
||||
garrow_cuda_context_set_property(GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
auto priv = GARROW_CUDA_CONTEXT_GET_PRIVATE(object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_CONTEXT:
|
||||
priv->context =
|
||||
*static_cast<std::shared_ptr<arrow::cuda::CudaContext> *>(g_value_get_pointer(value));
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
garrow_cuda_context_get_property(GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
switch (prop_id) {
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
garrow_cuda_context_init(GArrowCUDAContext *object)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
garrow_cuda_context_class_init(GArrowCUDAContextClass *klass)
|
||||
{
|
||||
GParamSpec *spec;
|
||||
|
||||
auto gobject_class = G_OBJECT_CLASS(klass);
|
||||
|
||||
gobject_class->finalize = garrow_cuda_context_finalize;
|
||||
gobject_class->set_property = garrow_cuda_context_set_property;
|
||||
gobject_class->get_property = garrow_cuda_context_get_property;
|
||||
|
||||
/**
|
||||
* GArrowCUDAContext:context:
|
||||
*
|
||||
* Since: 0.8.0
|
||||
*/
|
||||
spec = g_param_spec_pointer("context",
|
||||
"Context",
|
||||
"The raw std::shared_ptr<arrow::cuda::CudaContext>",
|
||||
static_cast<GParamFlags>(G_PARAM_WRITABLE |
|
||||
G_PARAM_CONSTRUCT_ONLY));
|
||||
g_object_class_install_property(gobject_class, PROP_CONTEXT, spec);
|
||||
}
|
||||
|
||||
/**
|
||||
* garrow_cuda_context_get_allocated_size:
|
||||
* @context: A #GArrowCUDAContext.
|
||||
*
|
||||
* Returns: The allocated memory by this context in bytes.
|
||||
*
|
||||
* Since: 0.8.0
|
||||
*/
|
||||
gint64
|
||||
garrow_cuda_context_get_allocated_size(GArrowCUDAContext *context)
|
||||
{
|
||||
auto arrow_context = garrow_cuda_context_get_raw(context);
|
||||
return arrow_context->bytes_allocated();
|
||||
}
|
||||
|
||||
|
||||
G_DEFINE_TYPE(GArrowCUDABuffer,
|
||||
garrow_cuda_buffer,
|
||||
GARROW_TYPE_BUFFER)
|
||||
|
||||
static void
|
||||
garrow_cuda_buffer_init(GArrowCUDABuffer *object)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
garrow_cuda_buffer_class_init(GArrowCUDABufferClass *klass)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* garrow_cuda_buffer_new:
|
||||
* @context: A #GArrowCUDAContext.
|
||||
* @size: The number of bytes to be allocated on GPU device for this context.
|
||||
* @error: (nullable): Return location for a #GError or %NULL.
|
||||
*
|
||||
* Returns: (transfer full): A newly created #GArrowCUDABuffer on
|
||||
* success, %NULL on error.
|
||||
*
|
||||
* Since: 0.8.0
|
||||
*/
|
||||
GArrowCUDABuffer *
|
||||
garrow_cuda_buffer_new(GArrowCUDAContext *context,
|
||||
gint64 size,
|
||||
GError **error)
|
||||
{
|
||||
auto arrow_context = garrow_cuda_context_get_raw(context);
|
||||
std::shared_ptr<arrow::cuda::CudaBuffer> arrow_buffer;
|
||||
auto status = arrow_context->Allocate(size, &arrow_buffer);
|
||||
if (garrow_error_check(error, status, "[cuda][buffer][new]")) {
|
||||
return garrow_cuda_buffer_new_raw(&arrow_buffer);
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* garrow_cuda_buffer_new_ipc:
|
||||
* @context: A #GArrowCUDAContext.
|
||||
* @handle: A #GArrowCUDAIPCMemoryHandle to be communicated.
|
||||
* @error: (nullable): Return location for a #GError or %NULL.
|
||||
*
|
||||
* Returns: (transfer full): A newly created #GArrowCUDABuffer on
|
||||
* success, %NULL on error. The buffer has data from the IPC target.
|
||||
*
|
||||
* Since: 0.8.0
|
||||
*/
|
||||
GArrowCUDABuffer *
|
||||
garrow_cuda_buffer_new_ipc(GArrowCUDAContext *context,
|
||||
GArrowCUDAIPCMemoryHandle *handle,
|
||||
GError **error)
|
||||
{
|
||||
auto arrow_context = garrow_cuda_context_get_raw(context);
|
||||
auto arrow_handle = garrow_cuda_ipc_memory_handle_get_raw(handle);
|
||||
std::shared_ptr<arrow::cuda::CudaBuffer> arrow_buffer;
|
||||
auto status = arrow_context->OpenIpcBuffer(*arrow_handle, &arrow_buffer);
|
||||
if (garrow_error_check(error, status,
|
||||
"[cuda][buffer][new-ipc]")) {
|
||||
return garrow_cuda_buffer_new_raw(&arrow_buffer);
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* garrow_cuda_buffer_new_record_batch:
|
||||
* @context: A #GArrowCUDAContext.
|
||||
* @record_batch: A #GArrowRecordBatch to be serialized.
|
||||
* @error: (nullable): Return location for a #GError or %NULL.
|
||||
*
|
||||
* Returns: (transfer full): A newly created #GArrowCUDABuffer on
|
||||
* success, %NULL on error. The buffer has serialized record batch
|
||||
* data.
|
||||
*
|
||||
* Since: 0.8.0
|
||||
*/
|
||||
GArrowCUDABuffer *
|
||||
garrow_cuda_buffer_new_record_batch(GArrowCUDAContext *context,
|
||||
GArrowRecordBatch *record_batch,
|
||||
GError **error)
|
||||
{
|
||||
auto arrow_context = garrow_cuda_context_get_raw(context);
|
||||
auto arrow_record_batch = garrow_record_batch_get_raw(record_batch);
|
||||
std::shared_ptr<arrow::cuda::CudaBuffer> arrow_buffer;
|
||||
auto status = arrow::cuda::SerializeRecordBatch(*arrow_record_batch,
|
||||
arrow_context.get(),
|
||||
&arrow_buffer);
|
||||
if (garrow_error_check(error, status,
|
||||
"[cuda][buffer][new-record-batch]")) {
|
||||
return garrow_cuda_buffer_new_raw(&arrow_buffer);
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* garrow_cuda_buffer_copy_to_host:
|
||||
* @buffer: A #GArrowCUDABuffer.
|
||||
* @position: The offset of memory on GPU device to be copied.
|
||||
* @size: The size of memory on GPU device to be copied in bytes.
|
||||
* @error: (nullable): Return location for a #GError or %NULL.
|
||||
*
|
||||
* Returns: (transfer full): A #GBytes that have copied memory on CPU
|
||||
* host on success, %NULL on error.
|
||||
*
|
||||
* Since: 0.8.0
|
||||
*/
|
||||
GBytes *
|
||||
garrow_cuda_buffer_copy_to_host(GArrowCUDABuffer *buffer,
|
||||
gint64 position,
|
||||
gint64 size,
|
||||
GError **error)
|
||||
{
|
||||
auto arrow_buffer = garrow_cuda_buffer_get_raw(buffer);
|
||||
auto data = static_cast<uint8_t *>(g_malloc(size));
|
||||
auto status = arrow_buffer->CopyToHost(position, size, data);
|
||||
if (garrow_error_check(error, status, "[cuda][buffer][copy-to-host]")) {
|
||||
return g_bytes_new_take(data, size);
|
||||
} else {
|
||||
g_free(data);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* garrow_cuda_buffer_copy_from_host:
|
||||
* @buffer: A #GArrowCUDABuffer.
|
||||
* @data: (array length=size): Data on CPU host to be copied.
|
||||
* @size: The size of data on CPU host to be copied in bytes.
|
||||
* @error: (nullable): Return location for a #GError or %NULL.
|
||||
*
|
||||
* Returns: %TRUE on success, %FALSE if there was an error.
|
||||
*
|
||||
* Since: 0.8.0
|
||||
*/
|
||||
gboolean
|
||||
garrow_cuda_buffer_copy_from_host(GArrowCUDABuffer *buffer,
|
||||
const guint8 *data,
|
||||
gint64 size,
|
||||
GError **error)
|
||||
{
|
||||
auto arrow_buffer = garrow_cuda_buffer_get_raw(buffer);
|
||||
auto status = arrow_buffer->CopyFromHost(0, data, size);
|
||||
return garrow_error_check(error,
|
||||
status,
|
||||
"[cuda][buffer][copy-from-host]");
|
||||
}
|
||||
|
||||
/**
|
||||
* garrow_cuda_buffer_export:
|
||||
* @buffer: A #GArrowCUDABuffer.
|
||||
* @error: (nullable): Return location for a #GError or %NULL.
|
||||
*
|
||||
* Returns: (transfer full): A newly created
|
||||
* #GArrowCUDAIPCMemoryHandle to handle the exported buffer on
|
||||
* success, %NULL on error
|
||||
*
|
||||
* Since: 0.8.0
|
||||
*/
|
||||
GArrowCUDAIPCMemoryHandle *
|
||||
garrow_cuda_buffer_export(GArrowCUDABuffer *buffer, GError **error)
|
||||
{
|
||||
auto arrow_buffer = garrow_cuda_buffer_get_raw(buffer);
|
||||
std::shared_ptr<arrow::cuda::CudaIpcMemHandle> arrow_handle;
|
||||
auto status = arrow_buffer->ExportForIpc(&arrow_handle);
|
||||
if (garrow_error_check(error, status, "[cuda][buffer][export-for-ipc]")) {
|
||||
return garrow_cuda_ipc_memory_handle_new_raw(&arrow_handle);
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* garrow_cuda_buffer_get_context:
|
||||
* @buffer: A #GArrowCUDABuffer.
|
||||
*
|
||||
* Returns: (transfer full): A newly created #GArrowCUDAContext for the
|
||||
* buffer. Contexts for the same buffer share the same data internally.
|
||||
*
|
||||
* Since: 0.8.0
|
||||
*/
|
||||
GArrowCUDAContext *
|
||||
garrow_cuda_buffer_get_context(GArrowCUDABuffer *buffer)
|
||||
{
|
||||
auto arrow_buffer = garrow_cuda_buffer_get_raw(buffer);
|
||||
auto arrow_context = arrow_buffer->context();
|
||||
return garrow_cuda_context_new_raw(&arrow_context);
|
||||
}
|
||||
|
||||
/**
|
||||
* garrow_cuda_buffer_read_record_batch:
|
||||
* @buffer: A #GArrowCUDABuffer.
|
||||
* @schema: A #GArrowSchema for record batch.
|
||||
* @error: (nullable): Return location for a #GError or %NULL.
|
||||
*
|
||||
* Returns: (transfer full): A newly created #GArrowRecordBatch on
|
||||
* success, %NULL on error. The record batch data is located on GPU.
|
||||
*
|
||||
* Since: 0.8.0
|
||||
*/
|
||||
GArrowRecordBatch *
|
||||
garrow_cuda_buffer_read_record_batch(GArrowCUDABuffer *buffer,
|
||||
GArrowSchema *schema,
|
||||
GError **error)
|
||||
{
|
||||
auto arrow_buffer = garrow_cuda_buffer_get_raw(buffer);
|
||||
auto arrow_schema = garrow_schema_get_raw(schema);
|
||||
auto pool = arrow::default_memory_pool();
|
||||
std::shared_ptr<arrow::RecordBatch> arrow_record_batch;
|
||||
auto status = arrow::cuda::ReadRecordBatch(arrow_schema,
|
||||
arrow_buffer,
|
||||
pool,
|
||||
&arrow_record_batch);
|
||||
if (garrow_error_check(error, status,
|
||||
"[cuda][buffer][read-record-batch]")) {
|
||||
return garrow_record_batch_new_raw(&arrow_record_batch);
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
G_DEFINE_TYPE(GArrowCUDAHostBuffer,
|
||||
garrow_cuda_host_buffer,
|
||||
GARROW_TYPE_MUTABLE_BUFFER)
|
||||
|
||||
static void
|
||||
garrow_cuda_host_buffer_init(GArrowCUDAHostBuffer *object)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
garrow_cuda_host_buffer_class_init(GArrowCUDAHostBufferClass *klass)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* garrow_cuda_host_buffer_new:
|
||||
* @gpu_number: A GPU device number for the target context.
|
||||
* @size: The number of bytes to be allocated on CPU host.
|
||||
* @error: (nullable): Return location for a #GError or %NULL.
|
||||
*
|
||||
* Returns: A newly created #GArrowCUDAHostBuffer on success,
|
||||
* %NULL on error. The allocated memory is accessible from GPU
|
||||
* device for the @context.
|
||||
*
|
||||
* Since: 0.8.0
|
||||
*/
|
||||
GArrowCUDAHostBuffer *
|
||||
garrow_cuda_host_buffer_new(gint gpu_number, gint64 size, GError **error)
|
||||
{
|
||||
arrow::cuda::CudaDeviceManager *manager;
|
||||
auto status = arrow::cuda::CudaDeviceManager::GetInstance(&manager);
|
||||
std::shared_ptr<arrow::cuda::CudaHostBuffer> arrow_buffer;
|
||||
status = manager->AllocateHost(gpu_number, size, &arrow_buffer);
|
||||
if (garrow_error_check(error, status, "[cuda][host-buffer][new]")) {
|
||||
return garrow_cuda_host_buffer_new_raw(&arrow_buffer);
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
typedef struct GArrowCUDAIPCMemoryHandlePrivate_ {
|
||||
std::shared_ptr<arrow::cuda::CudaIpcMemHandle> ipc_memory_handle;
|
||||
} GArrowCUDAIPCMemoryHandlePrivate;
|
||||
|
||||
enum {
|
||||
PROP_IPC_MEMORY_HANDLE = 1
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE_WITH_PRIVATE(GArrowCUDAIPCMemoryHandle,
|
||||
garrow_cuda_ipc_memory_handle,
|
||||
G_TYPE_OBJECT)
|
||||
|
||||
#define GARROW_CUDA_IPC_MEMORY_HANDLE_GET_PRIVATE(object) \
|
||||
static_cast<GArrowCUDAIPCMemoryHandlePrivate *>( \
|
||||
garrow_cuda_ipc_memory_handle_get_instance_private( \
|
||||
GARROW_CUDA_IPC_MEMORY_HANDLE(object)))
|
||||
|
||||
static void
|
||||
garrow_cuda_ipc_memory_handle_finalize(GObject *object)
|
||||
{
|
||||
auto priv = GARROW_CUDA_IPC_MEMORY_HANDLE_GET_PRIVATE(object);
|
||||
|
||||
priv->ipc_memory_handle = nullptr;
|
||||
|
||||
G_OBJECT_CLASS(garrow_cuda_ipc_memory_handle_parent_class)->finalize(object);
|
||||
}
|
||||
|
||||
static void
|
||||
garrow_cuda_ipc_memory_handle_set_property(GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
auto priv = GARROW_CUDA_IPC_MEMORY_HANDLE_GET_PRIVATE(object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_IPC_MEMORY_HANDLE:
|
||||
priv->ipc_memory_handle =
|
||||
*static_cast<std::shared_ptr<arrow::cuda::CudaIpcMemHandle> *>(g_value_get_pointer(value));
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
garrow_cuda_ipc_memory_handle_get_property(GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
switch (prop_id) {
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
garrow_cuda_ipc_memory_handle_init(GArrowCUDAIPCMemoryHandle *object)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
garrow_cuda_ipc_memory_handle_class_init(GArrowCUDAIPCMemoryHandleClass *klass)
|
||||
{
|
||||
GParamSpec *spec;
|
||||
|
||||
auto gobject_class = G_OBJECT_CLASS(klass);
|
||||
|
||||
gobject_class->finalize = garrow_cuda_ipc_memory_handle_finalize;
|
||||
gobject_class->set_property = garrow_cuda_ipc_memory_handle_set_property;
|
||||
gobject_class->get_property = garrow_cuda_ipc_memory_handle_get_property;
|
||||
|
||||
/**
|
||||
* GArrowCUDAIPCMemoryHandle:ipc-memory-handle:
|
||||
*
|
||||
* Since: 0.8.0
|
||||
*/
|
||||
spec = g_param_spec_pointer("ipc-memory-handle",
|
||||
"IPC Memory Handle",
|
||||
"The raw std::shared_ptr<arrow::cuda::CudaIpcMemHandle>",
|
||||
static_cast<GParamFlags>(G_PARAM_WRITABLE |
|
||||
G_PARAM_CONSTRUCT_ONLY));
|
||||
g_object_class_install_property(gobject_class, PROP_IPC_MEMORY_HANDLE, spec);
|
||||
}
|
||||
|
||||
/**
|
||||
* garrow_cuda_ipc_memory_handle_new:
|
||||
* @data: (array length=size): A serialized #GArrowCUDAIPCMemoryHandle.
|
||||
* @size: The size of data.
|
||||
* @error: (nullable): Return location for a #GError or %NULL.
|
||||
*
|
||||
* Returns: (transfer full): A newly created #GArrowCUDAIPCMemoryHandle
|
||||
* on success, %NULL on error.
|
||||
*
|
||||
* Since: 0.8.0
|
||||
*/
|
||||
GArrowCUDAIPCMemoryHandle *
|
||||
garrow_cuda_ipc_memory_handle_new(const guint8 *data,
|
||||
gsize size,
|
||||
GError **error)
|
||||
{
|
||||
std::shared_ptr<arrow::cuda::CudaIpcMemHandle> arrow_handle;
|
||||
auto status = arrow::cuda::CudaIpcMemHandle::FromBuffer(data, &arrow_handle);
|
||||
if (garrow_error_check(error, status,
|
||||
"[cuda][ipc-memory-handle][new]")) {
|
||||
return garrow_cuda_ipc_memory_handle_new_raw(&arrow_handle);
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* garrow_cuda_ipc_memory_handle_serialize:
|
||||
* @handle: A #GArrowCUDAIPCMemoryHandle.
|
||||
* @error: (nullable): Return location for a #GError or %NULL.
|
||||
*
|
||||
* Returns: (transfer full): A newly created #GArrowBuffer on success,
|
||||
* %NULL on error. The buffer has serialized @handle. The serialized
|
||||
* @handle can be deserialized by garrow_gpu_cuda_ipc_memory_handle_new()
|
||||
* in other process.
|
||||
*
|
||||
* Since: 0.8.0
|
||||
*/
|
||||
GArrowBuffer *
|
||||
garrow_cuda_ipc_memory_handle_serialize(GArrowCUDAIPCMemoryHandle *handle,
|
||||
GError **error)
|
||||
{
|
||||
auto arrow_handle = garrow_cuda_ipc_memory_handle_get_raw(handle);
|
||||
std::shared_ptr<arrow::Buffer> arrow_buffer;
|
||||
auto status = arrow_handle->Serialize(arrow::default_memory_pool(),
|
||||
&arrow_buffer);
|
||||
if (garrow_error_check(error, status,
|
||||
"[cuda][ipc-memory-handle][serialize]")) {
|
||||
return garrow_buffer_new_raw(&arrow_buffer);
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
GArrowBuffer *
|
||||
garrow_cuda_buffer_input_stream_new_raw_readable_interface(std::shared_ptr<arrow::Buffer> *arrow_buffer)
|
||||
{
|
||||
auto buffer = GARROW_BUFFER(g_object_new(GARROW_CUDA_TYPE_BUFFER,
|
||||
"buffer", arrow_buffer,
|
||||
NULL));
|
||||
return buffer;
|
||||
}
|
||||
|
||||
static std::shared_ptr<arrow::io::Readable>
|
||||
garrow_cuda_buffer_input_stream_get_raw_readable_interface(GArrowReadable *readable)
|
||||
{
|
||||
auto input_stream = GARROW_INPUT_STREAM(readable);
|
||||
auto arrow_input_stream = garrow_input_stream_get_raw(input_stream);
|
||||
return arrow_input_stream;
|
||||
}
|
||||
|
||||
static void
|
||||
garrow_cuda_buffer_input_stream_readable_interface_init(GArrowReadableInterface *iface)
|
||||
{
|
||||
iface->new_raw =
|
||||
garrow_cuda_buffer_input_stream_new_raw_readable_interface;
|
||||
iface->get_raw =
|
||||
garrow_cuda_buffer_input_stream_get_raw_readable_interface;
|
||||
}
|
||||
|
||||
G_DEFINE_TYPE_WITH_CODE(
|
||||
GArrowCUDABufferInputStream,
|
||||
garrow_cuda_buffer_input_stream,
|
||||
GARROW_TYPE_BUFFER_INPUT_STREAM,
|
||||
G_IMPLEMENT_INTERFACE(
|
||||
GARROW_TYPE_READABLE,
|
||||
garrow_cuda_buffer_input_stream_readable_interface_init))
|
||||
|
||||
static void
|
||||
garrow_cuda_buffer_input_stream_init(GArrowCUDABufferInputStream *object)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
garrow_cuda_buffer_input_stream_class_init(GArrowCUDABufferInputStreamClass *klass)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* garrow_cuda_buffer_input_stream_new:
|
||||
* @buffer: A #GArrowCUDABuffer.
|
||||
*
|
||||
* Returns: (transfer full): A newly created
|
||||
* #GArrowCUDABufferInputStream.
|
||||
*
|
||||
* Since: 0.8.0
|
||||
*/
|
||||
GArrowCUDABufferInputStream *
|
||||
garrow_cuda_buffer_input_stream_new(GArrowCUDABuffer *buffer)
|
||||
{
|
||||
auto arrow_buffer = garrow_cuda_buffer_get_raw(buffer);
|
||||
auto arrow_reader =
|
||||
std::make_shared<arrow::cuda::CudaBufferReader>(arrow_buffer);
|
||||
return garrow_cuda_buffer_input_stream_new_raw(&arrow_reader);
|
||||
}
|
||||
|
||||
|
||||
G_DEFINE_TYPE(GArrowCUDABufferOutputStream,
|
||||
garrow_cuda_buffer_output_stream,
|
||||
GARROW_TYPE_OUTPUT_STREAM)
|
||||
|
||||
static void
|
||||
garrow_cuda_buffer_output_stream_init(GArrowCUDABufferOutputStream *object)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
garrow_cuda_buffer_output_stream_class_init(GArrowCUDABufferOutputStreamClass *klass)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* garrow_cuda_buffer_output_stream_new:
|
||||
* @buffer: A #GArrowCUDABuffer.
|
||||
*
|
||||
* Returns: (transfer full): A newly created
|
||||
* #GArrowCUDABufferOutputStream.
|
||||
*
|
||||
* Since: 0.8.0
|
||||
*/
|
||||
GArrowCUDABufferOutputStream *
|
||||
garrow_cuda_buffer_output_stream_new(GArrowCUDABuffer *buffer)
|
||||
{
|
||||
auto arrow_buffer = garrow_cuda_buffer_get_raw(buffer);
|
||||
auto arrow_writer =
|
||||
std::make_shared<arrow::cuda::CudaBufferWriter>(arrow_buffer);
|
||||
return garrow_cuda_buffer_output_stream_new_raw(&arrow_writer);
|
||||
}
|
||||
|
||||
/**
|
||||
* garrow_cuda_buffer_output_stream_set_buffer_size:
|
||||
* @stream: A #GArrowCUDABufferOutputStream.
|
||||
* @size: A size of CPU buffer in bytes.
|
||||
* @error: (nullable): Return location for a #GError or %NULL.
|
||||
*
|
||||
* Returns: %TRUE on success, %FALSE if there was an error.
|
||||
*
|
||||
* Sets CPU buffer size. to limit `cudaMemcpy()` calls. If CPU buffer
|
||||
* size is `0`, buffering is disabled.
|
||||
*
|
||||
* The default is `0`.
|
||||
*
|
||||
* Since: 0.8.0
|
||||
*/
|
||||
gboolean
|
||||
garrow_cuda_buffer_output_stream_set_buffer_size(GArrowCUDABufferOutputStream *stream,
|
||||
gint64 size,
|
||||
GError **error)
|
||||
{
|
||||
auto arrow_stream = garrow_cuda_buffer_output_stream_get_raw(stream);
|
||||
auto status = arrow_stream->SetBufferSize(size);
|
||||
return garrow_error_check(error,
|
||||
status,
|
||||
"[cuda][buffer-output-stream][set-buffer-size]");
|
||||
}
|
||||
|
||||
/**
|
||||
* garrow_cuda_buffer_output_stream_get_buffer_size:
|
||||
* @stream: A #GArrowCUDABufferOutputStream.
|
||||
*
|
||||
* Returns: The CPU buffer size in bytes.
|
||||
*
|
||||
* See garrow_cuda_buffer_output_stream_set_buffer_size() for CPU
|
||||
* buffer size details.
|
||||
*
|
||||
* Since: 0.8.0
|
||||
*/
|
||||
gint64
|
||||
garrow_cuda_buffer_output_stream_get_buffer_size(GArrowCUDABufferOutputStream *stream)
|
||||
{
|
||||
auto arrow_stream = garrow_cuda_buffer_output_stream_get_raw(stream);
|
||||
return arrow_stream->buffer_size();
|
||||
}
|
||||
|
||||
/**
|
||||
* garrow_cuda_buffer_output_stream_get_buffered_size:
|
||||
* @stream: A #GArrowCUDABufferOutputStream.
|
||||
*
|
||||
* Returns: The size of buffered data in bytes.
|
||||
*
|
||||
* Since: 0.8.0
|
||||
*/
|
||||
gint64
|
||||
garrow_cuda_buffer_output_stream_get_buffered_size(GArrowCUDABufferOutputStream *stream)
|
||||
{
|
||||
auto arrow_stream = garrow_cuda_buffer_output_stream_get_raw(stream);
|
||||
return arrow_stream->num_bytes_buffered();
|
||||
}
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
GArrowCUDAContext *
|
||||
garrow_cuda_context_new_raw(std::shared_ptr<arrow::cuda::CudaContext> *arrow_context)
|
||||
{
|
||||
return GARROW_CUDA_CONTEXT(g_object_new(GARROW_CUDA_TYPE_CONTEXT,
|
||||
"context", arrow_context,
|
||||
NULL));
|
||||
}
|
||||
|
||||
std::shared_ptr<arrow::cuda::CudaContext>
|
||||
garrow_cuda_context_get_raw(GArrowCUDAContext *context)
|
||||
{
|
||||
if (!context)
|
||||
return nullptr;
|
||||
|
||||
auto priv = GARROW_CUDA_CONTEXT_GET_PRIVATE(context);
|
||||
return priv->context;
|
||||
}
|
||||
|
||||
GArrowCUDAIPCMemoryHandle *
|
||||
garrow_cuda_ipc_memory_handle_new_raw(std::shared_ptr<arrow::cuda::CudaIpcMemHandle> *arrow_handle)
|
||||
{
|
||||
auto handle = g_object_new(GARROW_CUDA_TYPE_IPC_MEMORY_HANDLE,
|
||||
"ipc-memory-handle", arrow_handle,
|
||||
NULL);
|
||||
return GARROW_CUDA_IPC_MEMORY_HANDLE(handle);
|
||||
}
|
||||
|
||||
std::shared_ptr<arrow::cuda::CudaIpcMemHandle>
|
||||
garrow_cuda_ipc_memory_handle_get_raw(GArrowCUDAIPCMemoryHandle *handle)
|
||||
{
|
||||
if (!handle)
|
||||
return nullptr;
|
||||
|
||||
auto priv = GARROW_CUDA_IPC_MEMORY_HANDLE_GET_PRIVATE(handle);
|
||||
return priv->ipc_memory_handle;
|
||||
}
|
||||
|
||||
GArrowCUDABuffer *
|
||||
garrow_cuda_buffer_new_raw(std::shared_ptr<arrow::cuda::CudaBuffer> *arrow_buffer)
|
||||
{
|
||||
return GARROW_CUDA_BUFFER(g_object_new(GARROW_CUDA_TYPE_BUFFER,
|
||||
"buffer", arrow_buffer,
|
||||
NULL));
|
||||
}
|
||||
|
||||
std::shared_ptr<arrow::cuda::CudaBuffer>
|
||||
garrow_cuda_buffer_get_raw(GArrowCUDABuffer *buffer)
|
||||
{
|
||||
if (!buffer)
|
||||
return nullptr;
|
||||
|
||||
auto arrow_buffer = garrow_buffer_get_raw(GARROW_BUFFER(buffer));
|
||||
return std::static_pointer_cast<arrow::cuda::CudaBuffer>(arrow_buffer);
|
||||
}
|
||||
|
||||
GArrowCUDAHostBuffer *
|
||||
garrow_cuda_host_buffer_new_raw(std::shared_ptr<arrow::cuda::CudaHostBuffer> *arrow_buffer)
|
||||
{
|
||||
auto buffer = g_object_new(GARROW_CUDA_TYPE_HOST_BUFFER,
|
||||
"buffer", arrow_buffer,
|
||||
NULL);
|
||||
return GARROW_CUDA_HOST_BUFFER(buffer);
|
||||
}
|
||||
|
||||
std::shared_ptr<arrow::cuda::CudaHostBuffer>
|
||||
garrow_cuda_host_buffer_get_raw(GArrowCUDAHostBuffer *buffer)
|
||||
{
|
||||
if (!buffer)
|
||||
return nullptr;
|
||||
|
||||
auto arrow_buffer = garrow_buffer_get_raw(GARROW_BUFFER(buffer));
|
||||
return std::static_pointer_cast<arrow::cuda::CudaHostBuffer>(arrow_buffer);
|
||||
}
|
||||
|
||||
GArrowCUDABufferInputStream *
|
||||
garrow_cuda_buffer_input_stream_new_raw(std::shared_ptr<arrow::cuda::CudaBufferReader> *arrow_reader)
|
||||
{
|
||||
auto input_stream = g_object_new(GARROW_CUDA_TYPE_BUFFER_INPUT_STREAM,
|
||||
"input-stream", arrow_reader,
|
||||
NULL);
|
||||
return GARROW_CUDA_BUFFER_INPUT_STREAM(input_stream);
|
||||
}
|
||||
|
||||
std::shared_ptr<arrow::cuda::CudaBufferReader>
|
||||
garrow_cuda_buffer_input_stream_get_raw(GArrowCUDABufferInputStream *input_stream)
|
||||
{
|
||||
if (!input_stream)
|
||||
return nullptr;
|
||||
|
||||
auto arrow_reader =
|
||||
garrow_input_stream_get_raw(GARROW_INPUT_STREAM(input_stream));
|
||||
return std::static_pointer_cast<arrow::cuda::CudaBufferReader>(arrow_reader);
|
||||
}
|
||||
|
||||
GArrowCUDABufferOutputStream *
|
||||
garrow_cuda_buffer_output_stream_new_raw(std::shared_ptr<arrow::cuda::CudaBufferWriter> *arrow_writer)
|
||||
{
|
||||
auto output_stream = g_object_new(GARROW_CUDA_TYPE_BUFFER_OUTPUT_STREAM,
|
||||
"output-stream", arrow_writer,
|
||||
NULL);
|
||||
return GARROW_CUDA_BUFFER_OUTPUT_STREAM(output_stream);
|
||||
}
|
||||
|
||||
std::shared_ptr<arrow::cuda::CudaBufferWriter>
|
||||
garrow_cuda_buffer_output_stream_get_raw(GArrowCUDABufferOutputStream *output_stream)
|
||||
{
|
||||
if (!output_stream)
|
||||
return nullptr;
|
||||
|
||||
auto arrow_writer =
|
||||
garrow_output_stream_get_raw(GARROW_OUTPUT_STREAM(output_stream));
|
||||
return std::static_pointer_cast<arrow::cuda::CudaBufferWriter>(arrow_writer);
|
||||
}
|
||||
@@ -0,0 +1,182 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <arrow-glib/arrow-glib.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define GARROW_CUDA_TYPE_DEVICE_MANAGER (garrow_cuda_device_manager_get_type())
|
||||
G_DECLARE_DERIVABLE_TYPE(GArrowCUDADeviceManager,
|
||||
garrow_cuda_device_manager,
|
||||
GARROW_CUDA,
|
||||
DEVICE_MANAGER,
|
||||
GObject)
|
||||
struct _GArrowCUDADeviceManagerClass
|
||||
{
|
||||
GObjectClass parent_class;
|
||||
};
|
||||
|
||||
#define GARROW_CUDA_TYPE_CONTEXT (garrow_cuda_context_get_type())
|
||||
G_DECLARE_DERIVABLE_TYPE(GArrowCUDAContext,
|
||||
garrow_cuda_context,
|
||||
GARROW_CUDA,
|
||||
CONTEXT,
|
||||
GObject)
|
||||
struct _GArrowCUDAContextClass
|
||||
{
|
||||
GObjectClass parent_class;
|
||||
};
|
||||
|
||||
#define GARROW_CUDA_TYPE_BUFFER (garrow_cuda_buffer_get_type())
|
||||
G_DECLARE_DERIVABLE_TYPE(GArrowCUDABuffer,
|
||||
garrow_cuda_buffer,
|
||||
GARROW_CUDA,
|
||||
BUFFER,
|
||||
GArrowBuffer)
|
||||
struct _GArrowCUDABufferClass
|
||||
{
|
||||
GArrowBufferClass parent_class;
|
||||
};
|
||||
|
||||
#define GARROW_CUDA_TYPE_HOST_BUFFER (garrow_cuda_host_buffer_get_type())
|
||||
G_DECLARE_DERIVABLE_TYPE(GArrowCUDAHostBuffer,
|
||||
garrow_cuda_host_buffer,
|
||||
GARROW_CUDA,
|
||||
HOST_BUFFER,
|
||||
GArrowMutableBuffer)
|
||||
struct _GArrowCUDAHostBufferClass
|
||||
{
|
||||
GArrowMutableBufferClass parent_class;
|
||||
};
|
||||
|
||||
#define GARROW_CUDA_TYPE_IPC_MEMORY_HANDLE \
|
||||
(garrow_cuda_ipc_memory_handle_get_type())
|
||||
G_DECLARE_DERIVABLE_TYPE(GArrowCUDAIPCMemoryHandle,
|
||||
garrow_cuda_ipc_memory_handle,
|
||||
GARROW_CUDA,
|
||||
IPC_MEMORY_HANDLE,
|
||||
GObject)
|
||||
struct _GArrowCUDAIPCMemoryHandleClass
|
||||
{
|
||||
GObjectClass parent_class;
|
||||
};
|
||||
|
||||
#define GARROW_CUDA_TYPE_BUFFER_INPUT_STREAM \
|
||||
(garrow_cuda_buffer_input_stream_get_type())
|
||||
G_DECLARE_DERIVABLE_TYPE(GArrowCUDABufferInputStream,
|
||||
garrow_cuda_buffer_input_stream,
|
||||
GARROW_CUDA,
|
||||
BUFFER_INPUT_STREAM,
|
||||
GArrowBufferInputStream)
|
||||
struct _GArrowCUDABufferInputStreamClass
|
||||
{
|
||||
GArrowBufferInputStreamClass parent_class;
|
||||
};
|
||||
|
||||
#define GARROW_CUDA_TYPE_BUFFER_OUTPUT_STREAM \
|
||||
(garrow_cuda_buffer_output_stream_get_type())
|
||||
G_DECLARE_DERIVABLE_TYPE(GArrowCUDABufferOutputStream,
|
||||
garrow_cuda_buffer_output_stream,
|
||||
GARROW_CUDA,
|
||||
BUFFER_OUTPUT_STREAM,
|
||||
GArrowOutputStream)
|
||||
struct _GArrowCUDABufferOutputStreamClass
|
||||
{
|
||||
GArrowOutputStreamClass parent_class;
|
||||
};
|
||||
|
||||
GArrowCUDADeviceManager *
|
||||
garrow_cuda_device_manager_new(GError **error);
|
||||
|
||||
GArrowCUDAContext *
|
||||
garrow_cuda_device_manager_get_context(GArrowCUDADeviceManager *manager,
|
||||
gint gpu_number,
|
||||
GError **error);
|
||||
gsize
|
||||
garrow_cuda_device_manager_get_n_devices(GArrowCUDADeviceManager *manager);
|
||||
|
||||
gint64
|
||||
garrow_cuda_context_get_allocated_size(GArrowCUDAContext *context);
|
||||
|
||||
|
||||
GArrowCUDABuffer *
|
||||
garrow_cuda_buffer_new(GArrowCUDAContext *context,
|
||||
gint64 size,
|
||||
GError **error);
|
||||
GArrowCUDABuffer *
|
||||
garrow_cuda_buffer_new_ipc(GArrowCUDAContext *context,
|
||||
GArrowCUDAIPCMemoryHandle *handle,
|
||||
GError **error);
|
||||
GArrowCUDABuffer *
|
||||
garrow_cuda_buffer_new_record_batch(GArrowCUDAContext *context,
|
||||
GArrowRecordBatch *record_batch,
|
||||
GError **error);
|
||||
GBytes *
|
||||
garrow_cuda_buffer_copy_to_host(GArrowCUDABuffer *buffer,
|
||||
gint64 position,
|
||||
gint64 size,
|
||||
GError **error);
|
||||
gboolean
|
||||
garrow_cuda_buffer_copy_from_host(GArrowCUDABuffer *buffer,
|
||||
const guint8 *data,
|
||||
gint64 size,
|
||||
GError **error);
|
||||
GArrowCUDAIPCMemoryHandle *
|
||||
garrow_cuda_buffer_export(GArrowCUDABuffer *buffer,
|
||||
GError **error);
|
||||
GArrowCUDAContext *
|
||||
garrow_cuda_buffer_get_context(GArrowCUDABuffer *buffer);
|
||||
GArrowRecordBatch *
|
||||
garrow_cuda_buffer_read_record_batch(GArrowCUDABuffer *buffer,
|
||||
GArrowSchema *schema,
|
||||
GError **error);
|
||||
|
||||
|
||||
GArrowCUDAHostBuffer *
|
||||
garrow_cuda_host_buffer_new(gint gpu_number,
|
||||
gint64 size,
|
||||
GError **error);
|
||||
|
||||
GArrowCUDAIPCMemoryHandle *
|
||||
garrow_cuda_ipc_memory_handle_new(const guint8 *data,
|
||||
gsize size,
|
||||
GError **error);
|
||||
|
||||
GArrowBuffer *
|
||||
garrow_cuda_ipc_memory_handle_serialize(GArrowCUDAIPCMemoryHandle *handle,
|
||||
GError **error);
|
||||
|
||||
GArrowCUDABufferInputStream *
|
||||
garrow_cuda_buffer_input_stream_new(GArrowCUDABuffer *buffer);
|
||||
|
||||
GArrowCUDABufferOutputStream *
|
||||
garrow_cuda_buffer_output_stream_new(GArrowCUDABuffer *buffer);
|
||||
|
||||
gboolean
|
||||
garrow_cuda_buffer_output_stream_set_buffer_size(GArrowCUDABufferOutputStream *stream,
|
||||
gint64 size,
|
||||
GError **error);
|
||||
gint64
|
||||
garrow_cuda_buffer_output_stream_get_buffer_size(GArrowCUDABufferOutputStream *stream);
|
||||
gint64
|
||||
garrow_cuda_buffer_output_stream_get_buffered_size(GArrowCUDABufferOutputStream *stream);
|
||||
|
||||
G_END_DECLS
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <arrow/gpu/cuda_api.h>
|
||||
|
||||
#include <arrow-cuda-glib/cuda.h>
|
||||
|
||||
GArrowCUDAContext *
|
||||
garrow_cuda_context_new_raw(std::shared_ptr<arrow::cuda::CudaContext> *arrow_context);
|
||||
std::shared_ptr<arrow::cuda::CudaContext>
|
||||
garrow_cuda_context_get_raw(GArrowCUDAContext *context);
|
||||
|
||||
GArrowCUDAIPCMemoryHandle *
|
||||
garrow_cuda_ipc_memory_handle_new_raw(std::shared_ptr<arrow::cuda::CudaIpcMemHandle> *arrow_handle);
|
||||
std::shared_ptr<arrow::cuda::CudaIpcMemHandle>
|
||||
garrow_cuda_ipc_memory_handle_get_raw(GArrowCUDAIPCMemoryHandle *handle);
|
||||
|
||||
GArrowCUDABuffer *
|
||||
garrow_cuda_buffer_new_raw(std::shared_ptr<arrow::cuda::CudaBuffer> *arrow_buffer);
|
||||
std::shared_ptr<arrow::cuda::CudaBuffer>
|
||||
garrow_cuda_buffer_get_raw(GArrowCUDABuffer *buffer);
|
||||
|
||||
GArrowCUDAHostBuffer *
|
||||
garrow_cuda_host_buffer_new_raw(std::shared_ptr<arrow::cuda::CudaHostBuffer> *arrow_buffer);
|
||||
std::shared_ptr<arrow::cuda::CudaHostBuffer>
|
||||
garrow_cuda_host_buffer_get_raw(GArrowCUDAHostBuffer *buffer);
|
||||
|
||||
GArrowCUDABufferInputStream *
|
||||
garrow_cuda_buffer_input_stream_new_raw(std::shared_ptr<arrow::cuda::CudaBufferReader> *arrow_reader);
|
||||
std::shared_ptr<arrow::cuda::CudaBufferReader>
|
||||
garrow_cuda_buffer_input_stream_get_raw(GArrowCUDABufferInputStream *input_stream);
|
||||
|
||||
GArrowCUDABufferOutputStream *
|
||||
garrow_cuda_buffer_output_stream_new_raw(std::shared_ptr<arrow::cuda::CudaBufferWriter> *arrow_writer);
|
||||
std::shared_ptr<arrow::cuda::CudaBufferWriter>
|
||||
garrow_cuda_buffer_output_stream_get_raw(GArrowCUDABufferOutputStream *output_stream);
|
||||
@@ -0,0 +1,79 @@
|
||||
# -*- indent-tabs-mode: nil -*-
|
||||
#
|
||||
# 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.
|
||||
|
||||
sources = files(
|
||||
'cuda.cpp',
|
||||
)
|
||||
|
||||
c_headers = files(
|
||||
'arrow-cuda-glib.h',
|
||||
'cuda.h',
|
||||
)
|
||||
|
||||
cpp_headers = files(
|
||||
'arrow-cuda-glib.hpp',
|
||||
'cuda.hpp',
|
||||
)
|
||||
|
||||
headers = c_headers + cpp_headers
|
||||
install_headers(headers, subdir: 'arrow-cuda-glib')
|
||||
|
||||
|
||||
dependencies = [
|
||||
arrow_cuda,
|
||||
arrow_glib,
|
||||
]
|
||||
libarrow_cuda_glib = library('arrow-cuda-glib',
|
||||
sources: sources,
|
||||
install: true,
|
||||
dependencies: dependencies,
|
||||
include_directories: base_include_directories,
|
||||
soversion: so_version,
|
||||
version: library_version)
|
||||
arrow_cuda_glib = declare_dependency(link_with: libarrow_cuda_glib,
|
||||
include_directories: base_include_directories,
|
||||
dependencies: dependencies)
|
||||
|
||||
pkgconfig.generate(filebase: 'arrow-cuda-glib',
|
||||
name: 'Apache Arrow CUDA GLib',
|
||||
description: 'C API for Apache Arrow CUDA based on GLib',
|
||||
version: version,
|
||||
requires: ['arrow-glib', 'arrow-cuda'],
|
||||
libraries: [libarrow_cuda_glib])
|
||||
|
||||
gir_dependencies = [
|
||||
declare_dependency(sources: arrow_glib_gir),
|
||||
]
|
||||
gir_extra_args = [
|
||||
'--warn-all',
|
||||
'--include-uninstalled=./arrow-glib/Arrow-1.0.gir',
|
||||
]
|
||||
arrow_cuda_glib_gir = gnome.generate_gir(libarrow_cuda_glib,
|
||||
dependencies: gir_dependencies,
|
||||
sources: sources + c_headers,
|
||||
namespace: 'ArrowCUDA',
|
||||
nsversion: api_version,
|
||||
identifier_prefix: 'GArrowCUDA',
|
||||
symbol_prefix: 'garrow_cuda',
|
||||
export_packages: 'arrow-cuda-glib',
|
||||
includes: [
|
||||
'Arrow-1.0',
|
||||
],
|
||||
install: true,
|
||||
extra_args: gir_extra_args)
|
||||
@@ -1,942 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <arrow-glib/buffer.hpp>
|
||||
#include <arrow-glib/error.hpp>
|
||||
#include <arrow-glib/input-stream.hpp>
|
||||
#include <arrow-glib/output-stream.hpp>
|
||||
#include <arrow-glib/readable.hpp>
|
||||
#include <arrow-glib/record-batch.hpp>
|
||||
#include <arrow-glib/schema.hpp>
|
||||
|
||||
#include <arrow-gpu-glib/cuda.hpp>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/**
|
||||
* SECTION: cuda
|
||||
* @section_id: cuda-classes
|
||||
* @title: CUDA related classes
|
||||
* @include: arrow-gpu-glib/arrow-gpu-glib.h
|
||||
*
|
||||
* The following classes provide CUDA support for Apache Arrow data.
|
||||
*
|
||||
* #GArrowGPUCUDADeviceManager is the starting point. You need at
|
||||
* least one #GArrowGPUCUDAContext to process Apache Arrow data on
|
||||
* NVIDIA GPU.
|
||||
*
|
||||
* #GArrowGPUCUDAContext is a class to keep context for one GPU. You
|
||||
* need to create #GArrowGPUCUDAContext for each GPU that you want to
|
||||
* use. You can create #GArrowGPUCUDAContext by
|
||||
* garrow_gpu_cuda_device_manager_get_context().
|
||||
*
|
||||
* #GArrowGPUCUDABuffer is a class for data on GPU. You can copy data
|
||||
* on GPU to/from CPU by garrow_gpu_cuda_buffer_copy_to_host() and
|
||||
* garrow_gpu_cuda_buffer_copy_from_host(). You can share data on GPU
|
||||
* with other processes by garrow_gpu_cuda_buffer_export() and
|
||||
* garrow_gpu_cuda_buffer_new_ipc().
|
||||
*
|
||||
* #GArrowGPUCUDAHostBuffer is a class for data on CPU that is
|
||||
* directly accessible from GPU.
|
||||
*
|
||||
* #GArrowGPUCUDAIPCMemoryHandle is a class to share data on GPU with
|
||||
* other processes. You can export your data on GPU to other processes
|
||||
* by garrow_gpu_cuda_buffer_export() and
|
||||
* garrow_gpu_cuda_ipc_memory_handle_new(). You can import other
|
||||
* process data on GPU by garrow_gpu_cuda_ipc_memory_handle_new() and
|
||||
* garrow_gpu_cuda_buffer_new_ipc().
|
||||
*
|
||||
* #GArrowGPUCUDABufferInputStream is a class to read data in
|
||||
* #GArrowGPUCUDABuffer.
|
||||
*
|
||||
* #GArrowGPUCUDABufferOutputStream is a class to write data into
|
||||
* #GArrowGPUCUDABuffer.
|
||||
*/
|
||||
|
||||
G_DEFINE_TYPE(GArrowGPUCUDADeviceManager,
|
||||
garrow_gpu_cuda_device_manager,
|
||||
G_TYPE_OBJECT)
|
||||
|
||||
static void
|
||||
garrow_gpu_cuda_device_manager_init(GArrowGPUCUDADeviceManager *object)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
garrow_gpu_cuda_device_manager_class_init(GArrowGPUCUDADeviceManagerClass *klass)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* garrow_gpu_cuda_device_manager_new:
|
||||
* @error: (nullable): Return location for a #GError or %NULL.
|
||||
*
|
||||
* Returns: A newly created #GArrowGPUCUDADeviceManager on success,
|
||||
* %NULL on error.
|
||||
*
|
||||
* Since: 0.8.0
|
||||
*/
|
||||
GArrowGPUCUDADeviceManager *
|
||||
garrow_gpu_cuda_device_manager_new(GError **error)
|
||||
{
|
||||
arrow::gpu::CudaDeviceManager *manager;
|
||||
auto status = arrow::gpu::CudaDeviceManager::GetInstance(&manager);
|
||||
if (garrow_error_check(error, status, "[gpu][cuda][device-manager][new]")) {
|
||||
auto manager = g_object_new(GARROW_GPU_TYPE_CUDA_DEVICE_MANAGER,
|
||||
NULL);
|
||||
return GARROW_GPU_CUDA_DEVICE_MANAGER(manager);
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* garrow_gpu_cuda_device_manager_get_context:
|
||||
* @manager: A #GArrowGPUCUDADeviceManager.
|
||||
* @gpu_number: A GPU device number for the target context.
|
||||
* @error: (nullable): Return location for a #GError or %NULL.
|
||||
*
|
||||
* Returns: (transfer full): A newly created #GArrowGPUCUDAContext on
|
||||
* success, %NULL on error. Contexts for the same GPU device number
|
||||
* share the same data internally.
|
||||
*
|
||||
* Since: 0.8.0
|
||||
*/
|
||||
GArrowGPUCUDAContext *
|
||||
garrow_gpu_cuda_device_manager_get_context(GArrowGPUCUDADeviceManager *manager,
|
||||
gint gpu_number,
|
||||
GError **error)
|
||||
{
|
||||
arrow::gpu::CudaDeviceManager *arrow_manager;
|
||||
arrow::gpu::CudaDeviceManager::GetInstance(&arrow_manager);
|
||||
std::shared_ptr<arrow::gpu::CudaContext> context;
|
||||
auto status = arrow_manager->GetContext(gpu_number, &context);
|
||||
if (garrow_error_check(error, status,
|
||||
"[gpu][cuda][device-manager][get-context]]")) {
|
||||
return garrow_gpu_cuda_context_new_raw(&context);
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* garrow_gpu_cuda_device_manager_get_n_devices:
|
||||
* @manager: A #GArrowGPUCUDADeviceManager.
|
||||
*
|
||||
* Returns: The number of GPU devices.
|
||||
*
|
||||
* Since: 0.8.0
|
||||
*/
|
||||
gsize
|
||||
garrow_gpu_cuda_device_manager_get_n_devices(GArrowGPUCUDADeviceManager *manager)
|
||||
{
|
||||
arrow::gpu::CudaDeviceManager *arrow_manager;
|
||||
arrow::gpu::CudaDeviceManager::GetInstance(&arrow_manager);
|
||||
return arrow_manager->num_devices();
|
||||
}
|
||||
|
||||
|
||||
typedef struct GArrowGPUCUDAContextPrivate_ {
|
||||
std::shared_ptr<arrow::gpu::CudaContext> context;
|
||||
} GArrowGPUCUDAContextPrivate;
|
||||
|
||||
enum {
|
||||
PROP_CONTEXT = 1
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE_WITH_PRIVATE(GArrowGPUCUDAContext,
|
||||
garrow_gpu_cuda_context,
|
||||
G_TYPE_OBJECT)
|
||||
|
||||
#define GARROW_GPU_CUDA_CONTEXT_GET_PRIVATE(object) \
|
||||
static_cast<GArrowGPUCUDAContextPrivate *>( \
|
||||
garrow_gpu_cuda_context_get_instance_private( \
|
||||
GARROW_GPU_CUDA_CONTEXT(object)))
|
||||
|
||||
static void
|
||||
garrow_gpu_cuda_context_finalize(GObject *object)
|
||||
{
|
||||
auto priv = GARROW_GPU_CUDA_CONTEXT_GET_PRIVATE(object);
|
||||
|
||||
priv->context = nullptr;
|
||||
|
||||
G_OBJECT_CLASS(garrow_gpu_cuda_context_parent_class)->finalize(object);
|
||||
}
|
||||
|
||||
static void
|
||||
garrow_gpu_cuda_context_set_property(GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
auto priv = GARROW_GPU_CUDA_CONTEXT_GET_PRIVATE(object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_CONTEXT:
|
||||
priv->context =
|
||||
*static_cast<std::shared_ptr<arrow::gpu::CudaContext> *>(g_value_get_pointer(value));
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
garrow_gpu_cuda_context_get_property(GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
switch (prop_id) {
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
garrow_gpu_cuda_context_init(GArrowGPUCUDAContext *object)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
garrow_gpu_cuda_context_class_init(GArrowGPUCUDAContextClass *klass)
|
||||
{
|
||||
GParamSpec *spec;
|
||||
|
||||
auto gobject_class = G_OBJECT_CLASS(klass);
|
||||
|
||||
gobject_class->finalize = garrow_gpu_cuda_context_finalize;
|
||||
gobject_class->set_property = garrow_gpu_cuda_context_set_property;
|
||||
gobject_class->get_property = garrow_gpu_cuda_context_get_property;
|
||||
|
||||
/**
|
||||
* GArrowGPUCUDAContext:context:
|
||||
*
|
||||
* Since: 0.8.0
|
||||
*/
|
||||
spec = g_param_spec_pointer("context",
|
||||
"Context",
|
||||
"The raw std::shared_ptr<arrow::gpu::CudaContext>",
|
||||
static_cast<GParamFlags>(G_PARAM_WRITABLE |
|
||||
G_PARAM_CONSTRUCT_ONLY));
|
||||
g_object_class_install_property(gobject_class, PROP_CONTEXT, spec);
|
||||
}
|
||||
|
||||
/**
|
||||
* garrow_gpu_cuda_context_get_allocated_size:
|
||||
* @context: A #GArrowGPUCUDAContext.
|
||||
*
|
||||
* Returns: The allocated memory by this context in bytes.
|
||||
*
|
||||
* Since: 0.8.0
|
||||
*/
|
||||
gint64
|
||||
garrow_gpu_cuda_context_get_allocated_size(GArrowGPUCUDAContext *context)
|
||||
{
|
||||
auto arrow_context = garrow_gpu_cuda_context_get_raw(context);
|
||||
return arrow_context->bytes_allocated();
|
||||
}
|
||||
|
||||
|
||||
G_DEFINE_TYPE(GArrowGPUCUDABuffer,
|
||||
garrow_gpu_cuda_buffer,
|
||||
GARROW_TYPE_BUFFER)
|
||||
|
||||
static void
|
||||
garrow_gpu_cuda_buffer_init(GArrowGPUCUDABuffer *object)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
garrow_gpu_cuda_buffer_class_init(GArrowGPUCUDABufferClass *klass)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* garrow_gpu_cuda_buffer_new:
|
||||
* @context: A #GArrowGPUCUDAContext.
|
||||
* @size: The number of bytes to be allocated on GPU device for this context.
|
||||
* @error: (nullable): Return location for a #GError or %NULL.
|
||||
*
|
||||
* Returns: (transfer full): A newly created #GArrowGPUCUDABuffer on
|
||||
* success, %NULL on error.
|
||||
*
|
||||
* Since: 0.8.0
|
||||
*/
|
||||
GArrowGPUCUDABuffer *
|
||||
garrow_gpu_cuda_buffer_new(GArrowGPUCUDAContext *context,
|
||||
gint64 size,
|
||||
GError **error)
|
||||
{
|
||||
auto arrow_context = garrow_gpu_cuda_context_get_raw(context);
|
||||
std::shared_ptr<arrow::gpu::CudaBuffer> arrow_buffer;
|
||||
auto status = arrow_context->Allocate(size, &arrow_buffer);
|
||||
if (garrow_error_check(error, status, "[gpu][cuda][buffer][new]")) {
|
||||
return garrow_gpu_cuda_buffer_new_raw(&arrow_buffer);
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* garrow_gpu_cuda_buffer_new_ipc:
|
||||
* @context: A #GArrowGPUCUDAContext.
|
||||
* @handle: A #GArrowGPUCUDAIPCMemoryHandle to be communicated.
|
||||
* @error: (nullable): Return location for a #GError or %NULL.
|
||||
*
|
||||
* Returns: (transfer full): A newly created #GArrowGPUCUDABuffer on
|
||||
* success, %NULL on error. The buffer has data from the IPC target.
|
||||
*
|
||||
* Since: 0.8.0
|
||||
*/
|
||||
GArrowGPUCUDABuffer *
|
||||
garrow_gpu_cuda_buffer_new_ipc(GArrowGPUCUDAContext *context,
|
||||
GArrowGPUCUDAIPCMemoryHandle *handle,
|
||||
GError **error)
|
||||
{
|
||||
auto arrow_context = garrow_gpu_cuda_context_get_raw(context);
|
||||
auto arrow_handle = garrow_gpu_cuda_ipc_memory_handle_get_raw(handle);
|
||||
std::shared_ptr<arrow::gpu::CudaBuffer> arrow_buffer;
|
||||
auto status = arrow_context->OpenIpcBuffer(*arrow_handle, &arrow_buffer);
|
||||
if (garrow_error_check(error, status,
|
||||
"[gpu][cuda][buffer][new-ipc]")) {
|
||||
return garrow_gpu_cuda_buffer_new_raw(&arrow_buffer);
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* garrow_gpu_cuda_buffer_new_record_batch:
|
||||
* @context: A #GArrowGPUCUDAContext.
|
||||
* @record_batch: A #GArrowRecordBatch to be serialized.
|
||||
* @error: (nullable): Return location for a #GError or %NULL.
|
||||
*
|
||||
* Returns: (transfer full): A newly created #GArrowGPUCUDABuffer on
|
||||
* success, %NULL on error. The buffer has serialized record batch
|
||||
* data.
|
||||
*
|
||||
* Since: 0.8.0
|
||||
*/
|
||||
GArrowGPUCUDABuffer *
|
||||
garrow_gpu_cuda_buffer_new_record_batch(GArrowGPUCUDAContext *context,
|
||||
GArrowRecordBatch *record_batch,
|
||||
GError **error)
|
||||
{
|
||||
auto arrow_context = garrow_gpu_cuda_context_get_raw(context);
|
||||
auto arrow_record_batch = garrow_record_batch_get_raw(record_batch);
|
||||
std::shared_ptr<arrow::gpu::CudaBuffer> arrow_buffer;
|
||||
auto status = arrow::gpu::SerializeRecordBatch(*arrow_record_batch,
|
||||
arrow_context.get(),
|
||||
&arrow_buffer);
|
||||
if (garrow_error_check(error, status,
|
||||
"[gpu][cuda][buffer][new-record-batch]")) {
|
||||
return garrow_gpu_cuda_buffer_new_raw(&arrow_buffer);
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* garrow_gpu_cuda_buffer_copy_to_host:
|
||||
* @buffer: A #GArrowGPUCUDABuffer.
|
||||
* @position: The offset of memory on GPU device to be copied.
|
||||
* @size: The size of memory on GPU device to be copied in bytes.
|
||||
* @error: (nullable): Return location for a #GError or %NULL.
|
||||
*
|
||||
* Returns: (transfer full): A #GBytes that have copied memory on CPU
|
||||
* host on success, %NULL on error.
|
||||
*
|
||||
* Since: 0.8.0
|
||||
*/
|
||||
GBytes *
|
||||
garrow_gpu_cuda_buffer_copy_to_host(GArrowGPUCUDABuffer *buffer,
|
||||
gint64 position,
|
||||
gint64 size,
|
||||
GError **error)
|
||||
{
|
||||
auto arrow_buffer = garrow_gpu_cuda_buffer_get_raw(buffer);
|
||||
auto data = static_cast<uint8_t *>(g_malloc(size));
|
||||
auto status = arrow_buffer->CopyToHost(position, size, data);
|
||||
if (garrow_error_check(error, status, "[gpu][cuda][buffer][copy-to-host]")) {
|
||||
return g_bytes_new_take(data, size);
|
||||
} else {
|
||||
g_free(data);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* garrow_gpu_cuda_buffer_copy_from_host:
|
||||
* @buffer: A #GArrowGPUCUDABuffer.
|
||||
* @data: (array length=size): Data on CPU host to be copied.
|
||||
* @size: The size of data on CPU host to be copied in bytes.
|
||||
* @error: (nullable): Return location for a #GError or %NULL.
|
||||
*
|
||||
* Returns: %TRUE on success, %FALSE if there was an error.
|
||||
*
|
||||
* Since: 0.8.0
|
||||
*/
|
||||
gboolean
|
||||
garrow_gpu_cuda_buffer_copy_from_host(GArrowGPUCUDABuffer *buffer,
|
||||
const guint8 *data,
|
||||
gint64 size,
|
||||
GError **error)
|
||||
{
|
||||
auto arrow_buffer = garrow_gpu_cuda_buffer_get_raw(buffer);
|
||||
auto status = arrow_buffer->CopyFromHost(0, data, size);
|
||||
return garrow_error_check(error,
|
||||
status,
|
||||
"[gpu][cuda][buffer][copy-from-host]");
|
||||
}
|
||||
|
||||
/**
|
||||
* garrow_gpu_cuda_buffer_export:
|
||||
* @buffer: A #GArrowGPUCUDABuffer.
|
||||
* @error: (nullable): Return location for a #GError or %NULL.
|
||||
*
|
||||
* Returns: (transfer full): A newly created
|
||||
* #GArrowGPUCUDAIPCMemoryHandle to handle the exported buffer on
|
||||
* success, %NULL on error
|
||||
*
|
||||
* Since: 0.8.0
|
||||
*/
|
||||
GArrowGPUCUDAIPCMemoryHandle *
|
||||
garrow_gpu_cuda_buffer_export(GArrowGPUCUDABuffer *buffer, GError **error)
|
||||
{
|
||||
auto arrow_buffer = garrow_gpu_cuda_buffer_get_raw(buffer);
|
||||
std::shared_ptr<arrow::gpu::CudaIpcMemHandle> arrow_handle;
|
||||
auto status = arrow_buffer->ExportForIpc(&arrow_handle);
|
||||
if (garrow_error_check(error, status, "[gpu][cuda][buffer][export-for-ipc]")) {
|
||||
return garrow_gpu_cuda_ipc_memory_handle_new_raw(&arrow_handle);
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* garrow_gpu_cuda_buffer_get_context:
|
||||
* @buffer: A #GArrowGPUCUDABuffer.
|
||||
*
|
||||
* Returns: (transfer full): A newly created #GArrowGPUCUDAContext for the
|
||||
* buffer. Contexts for the same buffer share the same data internally.
|
||||
*
|
||||
* Since: 0.8.0
|
||||
*/
|
||||
GArrowGPUCUDAContext *
|
||||
garrow_gpu_cuda_buffer_get_context(GArrowGPUCUDABuffer *buffer)
|
||||
{
|
||||
auto arrow_buffer = garrow_gpu_cuda_buffer_get_raw(buffer);
|
||||
auto arrow_context = arrow_buffer->context();
|
||||
return garrow_gpu_cuda_context_new_raw(&arrow_context);
|
||||
}
|
||||
|
||||
/**
|
||||
* garrow_gpu_cuda_buffer_read_record_batch:
|
||||
* @buffer: A #GArrowGPUCUDABuffer.
|
||||
* @schema: A #GArrowSchema for record batch.
|
||||
* @error: (nullable): Return location for a #GError or %NULL.
|
||||
*
|
||||
* Returns: (transfer full): A newly created #GArrowRecordBatch on
|
||||
* success, %NULL on error. The record batch data is located on GPU.
|
||||
*
|
||||
* Since: 0.8.0
|
||||
*/
|
||||
GArrowRecordBatch *
|
||||
garrow_gpu_cuda_buffer_read_record_batch(GArrowGPUCUDABuffer *buffer,
|
||||
GArrowSchema *schema,
|
||||
GError **error)
|
||||
{
|
||||
auto arrow_buffer = garrow_gpu_cuda_buffer_get_raw(buffer);
|
||||
auto arrow_schema = garrow_schema_get_raw(schema);
|
||||
auto pool = arrow::default_memory_pool();
|
||||
std::shared_ptr<arrow::RecordBatch> arrow_record_batch;
|
||||
auto status = arrow::gpu::ReadRecordBatch(arrow_schema,
|
||||
arrow_buffer,
|
||||
pool,
|
||||
&arrow_record_batch);
|
||||
if (garrow_error_check(error, status,
|
||||
"[gpu][cuda][buffer][read-record-batch]")) {
|
||||
return garrow_record_batch_new_raw(&arrow_record_batch);
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
G_DEFINE_TYPE(GArrowGPUCUDAHostBuffer,
|
||||
garrow_gpu_cuda_host_buffer,
|
||||
GARROW_TYPE_MUTABLE_BUFFER)
|
||||
|
||||
static void
|
||||
garrow_gpu_cuda_host_buffer_init(GArrowGPUCUDAHostBuffer *object)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
garrow_gpu_cuda_host_buffer_class_init(GArrowGPUCUDAHostBufferClass *klass)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* garrow_gpu_cuda_host_buffer_new:
|
||||
* @gpu_number: A GPU device number for the target context.
|
||||
* @size: The number of bytes to be allocated on CPU host.
|
||||
* @error: (nullable): Return location for a #GError or %NULL.
|
||||
*
|
||||
* Returns: A newly created #GArrowGPUCUDAHostBuffer on success,
|
||||
* %NULL on error. The allocated memory is accessible from GPU
|
||||
* device for the @context.
|
||||
*
|
||||
* Since: 0.8.0
|
||||
*/
|
||||
GArrowGPUCUDAHostBuffer *
|
||||
garrow_gpu_cuda_host_buffer_new(gint gpu_number, gint64 size, GError **error)
|
||||
{
|
||||
arrow::gpu::CudaDeviceManager *manager;
|
||||
auto status = arrow::gpu::CudaDeviceManager::GetInstance(&manager);
|
||||
std::shared_ptr<arrow::gpu::CudaHostBuffer> arrow_buffer;
|
||||
status = manager->AllocateHost(gpu_number, size, &arrow_buffer);
|
||||
if (garrow_error_check(error, status, "[gpu][cuda][host-buffer][new]")) {
|
||||
return garrow_gpu_cuda_host_buffer_new_raw(&arrow_buffer);
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
typedef struct GArrowGPUCUDAIPCMemoryHandlePrivate_ {
|
||||
std::shared_ptr<arrow::gpu::CudaIpcMemHandle> ipc_memory_handle;
|
||||
} GArrowGPUCUDAIPCMemoryHandlePrivate;
|
||||
|
||||
enum {
|
||||
PROP_IPC_MEMORY_HANDLE = 1
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE_WITH_PRIVATE(GArrowGPUCUDAIPCMemoryHandle,
|
||||
garrow_gpu_cuda_ipc_memory_handle,
|
||||
G_TYPE_OBJECT)
|
||||
|
||||
#define GARROW_GPU_CUDA_IPC_MEMORY_HANDLE_GET_PRIVATE(object) \
|
||||
static_cast<GArrowGPUCUDAIPCMemoryHandlePrivate *>( \
|
||||
garrow_gpu_cuda_ipc_memory_handle_get_instance_private( \
|
||||
GARROW_GPU_CUDA_IPC_MEMORY_HANDLE(object)))
|
||||
|
||||
static void
|
||||
garrow_gpu_cuda_ipc_memory_handle_finalize(GObject *object)
|
||||
{
|
||||
auto priv = GARROW_GPU_CUDA_IPC_MEMORY_HANDLE_GET_PRIVATE(object);
|
||||
|
||||
priv->ipc_memory_handle = nullptr;
|
||||
|
||||
G_OBJECT_CLASS(garrow_gpu_cuda_ipc_memory_handle_parent_class)->finalize(object);
|
||||
}
|
||||
|
||||
static void
|
||||
garrow_gpu_cuda_ipc_memory_handle_set_property(GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
auto priv = GARROW_GPU_CUDA_IPC_MEMORY_HANDLE_GET_PRIVATE(object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_IPC_MEMORY_HANDLE:
|
||||
priv->ipc_memory_handle =
|
||||
*static_cast<std::shared_ptr<arrow::gpu::CudaIpcMemHandle> *>(g_value_get_pointer(value));
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
garrow_gpu_cuda_ipc_memory_handle_get_property(GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
switch (prop_id) {
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
garrow_gpu_cuda_ipc_memory_handle_init(GArrowGPUCUDAIPCMemoryHandle *object)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
garrow_gpu_cuda_ipc_memory_handle_class_init(GArrowGPUCUDAIPCMemoryHandleClass *klass)
|
||||
{
|
||||
GParamSpec *spec;
|
||||
|
||||
auto gobject_class = G_OBJECT_CLASS(klass);
|
||||
|
||||
gobject_class->finalize = garrow_gpu_cuda_ipc_memory_handle_finalize;
|
||||
gobject_class->set_property = garrow_gpu_cuda_ipc_memory_handle_set_property;
|
||||
gobject_class->get_property = garrow_gpu_cuda_ipc_memory_handle_get_property;
|
||||
|
||||
/**
|
||||
* GArrowGPUCUDAIPCMemoryHandle:ipc-memory-handle:
|
||||
*
|
||||
* Since: 0.8.0
|
||||
*/
|
||||
spec = g_param_spec_pointer("ipc-memory-handle",
|
||||
"IPC Memory Handle",
|
||||
"The raw std::shared_ptr<arrow::gpu::CudaIpcMemHandle>",
|
||||
static_cast<GParamFlags>(G_PARAM_WRITABLE |
|
||||
G_PARAM_CONSTRUCT_ONLY));
|
||||
g_object_class_install_property(gobject_class, PROP_IPC_MEMORY_HANDLE, spec);
|
||||
}
|
||||
|
||||
/**
|
||||
* garrow_gpu_cuda_ipc_memory_handle_new:
|
||||
* @data: (array length=size): A serialized #GArrowGPUCUDAIPCMemoryHandle.
|
||||
* @size: The size of data.
|
||||
* @error: (nullable): Return location for a #GError or %NULL.
|
||||
*
|
||||
* Returns: (transfer full): A newly created #GArrowGPUCUDAIPCMemoryHandle
|
||||
* on success, %NULL on error.
|
||||
*
|
||||
* Since: 0.8.0
|
||||
*/
|
||||
GArrowGPUCUDAIPCMemoryHandle *
|
||||
garrow_gpu_cuda_ipc_memory_handle_new(const guint8 *data,
|
||||
gsize size,
|
||||
GError **error)
|
||||
{
|
||||
std::shared_ptr<arrow::gpu::CudaIpcMemHandle> arrow_handle;
|
||||
auto status = arrow::gpu::CudaIpcMemHandle::FromBuffer(data, &arrow_handle);
|
||||
if (garrow_error_check(error, status,
|
||||
"[gpu][cuda][ipc-memory-handle][new]")) {
|
||||
return garrow_gpu_cuda_ipc_memory_handle_new_raw(&arrow_handle);
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* garrow_gpu_cuda_ipc_memory_handle_serialize:
|
||||
* @handle: A #GArrowGPUCUDAIPCMemoryHandle.
|
||||
* @error: (nullable): Return location for a #GError or %NULL.
|
||||
*
|
||||
* Returns: (transfer full): A newly created #GArrowBuffer on success,
|
||||
* %NULL on error. The buffer has serialized @handle. The serialized
|
||||
* @handle can be deserialized by garrow_gpu_cuda_ipc_memory_handle_new()
|
||||
* in other process.
|
||||
*
|
||||
* Since: 0.8.0
|
||||
*/
|
||||
GArrowBuffer *
|
||||
garrow_gpu_cuda_ipc_memory_handle_serialize(GArrowGPUCUDAIPCMemoryHandle *handle,
|
||||
GError **error)
|
||||
{
|
||||
auto arrow_handle = garrow_gpu_cuda_ipc_memory_handle_get_raw(handle);
|
||||
std::shared_ptr<arrow::Buffer> arrow_buffer;
|
||||
auto status = arrow_handle->Serialize(arrow::default_memory_pool(),
|
||||
&arrow_buffer);
|
||||
if (garrow_error_check(error, status,
|
||||
"[gpu][cuda][ipc-memory-handle][serialize]")) {
|
||||
return garrow_buffer_new_raw(&arrow_buffer);
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
GArrowBuffer *
|
||||
garrow_gpu_cuda_buffer_input_stream_new_raw_readable_interface(std::shared_ptr<arrow::Buffer> *arrow_buffer)
|
||||
{
|
||||
auto buffer = GARROW_BUFFER(g_object_new(GARROW_GPU_TYPE_CUDA_BUFFER,
|
||||
"buffer", arrow_buffer,
|
||||
NULL));
|
||||
return buffer;
|
||||
}
|
||||
|
||||
static std::shared_ptr<arrow::io::Readable>
|
||||
garrow_gpu_cuda_buffer_input_stream_get_raw_readable_interface(GArrowReadable *readable)
|
||||
{
|
||||
auto input_stream = GARROW_INPUT_STREAM(readable);
|
||||
auto arrow_input_stream = garrow_input_stream_get_raw(input_stream);
|
||||
return arrow_input_stream;
|
||||
}
|
||||
|
||||
static void
|
||||
garrow_gpu_cuda_buffer_input_stream_readable_interface_init(GArrowReadableInterface *iface)
|
||||
{
|
||||
iface->new_raw =
|
||||
garrow_gpu_cuda_buffer_input_stream_new_raw_readable_interface;
|
||||
iface->get_raw =
|
||||
garrow_gpu_cuda_buffer_input_stream_get_raw_readable_interface;
|
||||
}
|
||||
|
||||
G_DEFINE_TYPE_WITH_CODE(
|
||||
GArrowGPUCUDABufferInputStream,
|
||||
garrow_gpu_cuda_buffer_input_stream,
|
||||
GARROW_TYPE_BUFFER_INPUT_STREAM,
|
||||
G_IMPLEMENT_INTERFACE(
|
||||
GARROW_TYPE_READABLE,
|
||||
garrow_gpu_cuda_buffer_input_stream_readable_interface_init))
|
||||
|
||||
static void
|
||||
garrow_gpu_cuda_buffer_input_stream_init(GArrowGPUCUDABufferInputStream *object)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
garrow_gpu_cuda_buffer_input_stream_class_init(GArrowGPUCUDABufferInputStreamClass *klass)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* garrow_gpu_cuda_buffer_input_stream_new:
|
||||
* @buffer: A #GArrowGPUCUDABuffer.
|
||||
*
|
||||
* Returns: (transfer full): A newly created
|
||||
* #GArrowGPUCUDABufferInputStream.
|
||||
*
|
||||
* Since: 0.8.0
|
||||
*/
|
||||
GArrowGPUCUDABufferInputStream *
|
||||
garrow_gpu_cuda_buffer_input_stream_new(GArrowGPUCUDABuffer *buffer)
|
||||
{
|
||||
auto arrow_buffer = garrow_gpu_cuda_buffer_get_raw(buffer);
|
||||
auto arrow_reader =
|
||||
std::make_shared<arrow::gpu::CudaBufferReader>(arrow_buffer);
|
||||
return garrow_gpu_cuda_buffer_input_stream_new_raw(&arrow_reader);
|
||||
}
|
||||
|
||||
|
||||
G_DEFINE_TYPE(GArrowGPUCUDABufferOutputStream,
|
||||
garrow_gpu_cuda_buffer_output_stream,
|
||||
GARROW_TYPE_OUTPUT_STREAM)
|
||||
|
||||
static void
|
||||
garrow_gpu_cuda_buffer_output_stream_init(GArrowGPUCUDABufferOutputStream *object)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
garrow_gpu_cuda_buffer_output_stream_class_init(GArrowGPUCUDABufferOutputStreamClass *klass)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* garrow_gpu_cuda_buffer_output_stream_new:
|
||||
* @buffer: A #GArrowGPUCUDABuffer.
|
||||
*
|
||||
* Returns: (transfer full): A newly created
|
||||
* #GArrowGPUCUDABufferOutputStream.
|
||||
*
|
||||
* Since: 0.8.0
|
||||
*/
|
||||
GArrowGPUCUDABufferOutputStream *
|
||||
garrow_gpu_cuda_buffer_output_stream_new(GArrowGPUCUDABuffer *buffer)
|
||||
{
|
||||
auto arrow_buffer = garrow_gpu_cuda_buffer_get_raw(buffer);
|
||||
auto arrow_writer =
|
||||
std::make_shared<arrow::gpu::CudaBufferWriter>(arrow_buffer);
|
||||
return garrow_gpu_cuda_buffer_output_stream_new_raw(&arrow_writer);
|
||||
}
|
||||
|
||||
/**
|
||||
* garrow_gpu_cuda_buffer_output_stream_set_buffer_size:
|
||||
* @stream: A #GArrowGPUCUDABufferOutputStream.
|
||||
* @size: A size of CPU buffer in bytes.
|
||||
* @error: (nullable): Return location for a #GError or %NULL.
|
||||
*
|
||||
* Returns: %TRUE on success, %FALSE if there was an error.
|
||||
*
|
||||
* Sets CPU buffer size. to limit `cudaMemcpy()` calls. If CPU buffer
|
||||
* size is `0`, buffering is disabled.
|
||||
*
|
||||
* The default is `0`.
|
||||
*
|
||||
* Since: 0.8.0
|
||||
*/
|
||||
gboolean
|
||||
garrow_gpu_cuda_buffer_output_stream_set_buffer_size(GArrowGPUCUDABufferOutputStream *stream,
|
||||
gint64 size,
|
||||
GError **error)
|
||||
{
|
||||
auto arrow_stream = garrow_gpu_cuda_buffer_output_stream_get_raw(stream);
|
||||
auto status = arrow_stream->SetBufferSize(size);
|
||||
return garrow_error_check(error,
|
||||
status,
|
||||
"[gpu][cuda][buffer-output-stream][set-buffer-size]");
|
||||
}
|
||||
|
||||
/**
|
||||
* garrow_gpu_cuda_buffer_output_stream_get_buffer_size:
|
||||
* @stream: A #GArrowGPUCUDABufferOutputStream.
|
||||
*
|
||||
* Returns: The CPU buffer size in bytes.
|
||||
*
|
||||
* See garrow_gpu_cuda_buffer_output_stream_set_buffer_size() for CPU
|
||||
* buffer size details.
|
||||
*
|
||||
* Since: 0.8.0
|
||||
*/
|
||||
gint64
|
||||
garrow_gpu_cuda_buffer_output_stream_get_buffer_size(GArrowGPUCUDABufferOutputStream *stream)
|
||||
{
|
||||
auto arrow_stream = garrow_gpu_cuda_buffer_output_stream_get_raw(stream);
|
||||
return arrow_stream->buffer_size();
|
||||
}
|
||||
|
||||
/**
|
||||
* garrow_gpu_cuda_buffer_output_stream_get_buffered_size:
|
||||
* @stream: A #GArrowGPUCUDABufferOutputStream.
|
||||
*
|
||||
* Returns: The size of buffered data in bytes.
|
||||
*
|
||||
* Since: 0.8.0
|
||||
*/
|
||||
gint64
|
||||
garrow_gpu_cuda_buffer_output_stream_get_buffered_size(GArrowGPUCUDABufferOutputStream *stream)
|
||||
{
|
||||
auto arrow_stream = garrow_gpu_cuda_buffer_output_stream_get_raw(stream);
|
||||
return arrow_stream->num_bytes_buffered();
|
||||
}
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
GArrowGPUCUDAContext *
|
||||
garrow_gpu_cuda_context_new_raw(std::shared_ptr<arrow::gpu::CudaContext> *arrow_context)
|
||||
{
|
||||
return GARROW_GPU_CUDA_CONTEXT(g_object_new(GARROW_GPU_TYPE_CUDA_CONTEXT,
|
||||
"context", arrow_context,
|
||||
NULL));
|
||||
}
|
||||
|
||||
std::shared_ptr<arrow::gpu::CudaContext>
|
||||
garrow_gpu_cuda_context_get_raw(GArrowGPUCUDAContext *context)
|
||||
{
|
||||
if (!context)
|
||||
return nullptr;
|
||||
|
||||
auto priv = GARROW_GPU_CUDA_CONTEXT_GET_PRIVATE(context);
|
||||
return priv->context;
|
||||
}
|
||||
|
||||
GArrowGPUCUDAIPCMemoryHandle *
|
||||
garrow_gpu_cuda_ipc_memory_handle_new_raw(std::shared_ptr<arrow::gpu::CudaIpcMemHandle> *arrow_handle)
|
||||
{
|
||||
auto handle = g_object_new(GARROW_GPU_TYPE_CUDA_IPC_MEMORY_HANDLE,
|
||||
"ipc-memory-handle", arrow_handle,
|
||||
NULL);
|
||||
return GARROW_GPU_CUDA_IPC_MEMORY_HANDLE(handle);
|
||||
}
|
||||
|
||||
std::shared_ptr<arrow::gpu::CudaIpcMemHandle>
|
||||
garrow_gpu_cuda_ipc_memory_handle_get_raw(GArrowGPUCUDAIPCMemoryHandle *handle)
|
||||
{
|
||||
if (!handle)
|
||||
return nullptr;
|
||||
|
||||
auto priv = GARROW_GPU_CUDA_IPC_MEMORY_HANDLE_GET_PRIVATE(handle);
|
||||
return priv->ipc_memory_handle;
|
||||
}
|
||||
|
||||
GArrowGPUCUDABuffer *
|
||||
garrow_gpu_cuda_buffer_new_raw(std::shared_ptr<arrow::gpu::CudaBuffer> *arrow_buffer)
|
||||
{
|
||||
return GARROW_GPU_CUDA_BUFFER(g_object_new(GARROW_GPU_TYPE_CUDA_BUFFER,
|
||||
"buffer", arrow_buffer,
|
||||
NULL));
|
||||
}
|
||||
|
||||
std::shared_ptr<arrow::gpu::CudaBuffer>
|
||||
garrow_gpu_cuda_buffer_get_raw(GArrowGPUCUDABuffer *buffer)
|
||||
{
|
||||
if (!buffer)
|
||||
return nullptr;
|
||||
|
||||
auto arrow_buffer = garrow_buffer_get_raw(GARROW_BUFFER(buffer));
|
||||
return std::static_pointer_cast<arrow::gpu::CudaBuffer>(arrow_buffer);
|
||||
}
|
||||
|
||||
GArrowGPUCUDAHostBuffer *
|
||||
garrow_gpu_cuda_host_buffer_new_raw(std::shared_ptr<arrow::gpu::CudaHostBuffer> *arrow_buffer)
|
||||
{
|
||||
auto buffer = g_object_new(GARROW_GPU_TYPE_CUDA_HOST_BUFFER,
|
||||
"buffer", arrow_buffer,
|
||||
NULL);
|
||||
return GARROW_GPU_CUDA_HOST_BUFFER(buffer);
|
||||
}
|
||||
|
||||
std::shared_ptr<arrow::gpu::CudaHostBuffer>
|
||||
garrow_gpu_cuda_host_buffer_get_raw(GArrowGPUCUDAHostBuffer *buffer)
|
||||
{
|
||||
if (!buffer)
|
||||
return nullptr;
|
||||
|
||||
auto arrow_buffer = garrow_buffer_get_raw(GARROW_BUFFER(buffer));
|
||||
return std::static_pointer_cast<arrow::gpu::CudaHostBuffer>(arrow_buffer);
|
||||
}
|
||||
|
||||
GArrowGPUCUDABufferInputStream *
|
||||
garrow_gpu_cuda_buffer_input_stream_new_raw(std::shared_ptr<arrow::gpu::CudaBufferReader> *arrow_reader)
|
||||
{
|
||||
auto input_stream = g_object_new(GARROW_GPU_TYPE_CUDA_BUFFER_INPUT_STREAM,
|
||||
"input-stream", arrow_reader,
|
||||
NULL);
|
||||
return GARROW_GPU_CUDA_BUFFER_INPUT_STREAM(input_stream);
|
||||
}
|
||||
|
||||
std::shared_ptr<arrow::gpu::CudaBufferReader>
|
||||
garrow_gpu_cuda_buffer_input_stream_get_raw(GArrowGPUCUDABufferInputStream *input_stream)
|
||||
{
|
||||
if (!input_stream)
|
||||
return nullptr;
|
||||
|
||||
auto arrow_reader =
|
||||
garrow_input_stream_get_raw(GARROW_INPUT_STREAM(input_stream));
|
||||
return std::static_pointer_cast<arrow::gpu::CudaBufferReader>(arrow_reader);
|
||||
}
|
||||
|
||||
GArrowGPUCUDABufferOutputStream *
|
||||
garrow_gpu_cuda_buffer_output_stream_new_raw(std::shared_ptr<arrow::gpu::CudaBufferWriter> *arrow_writer)
|
||||
{
|
||||
auto output_stream = g_object_new(GARROW_GPU_TYPE_CUDA_BUFFER_OUTPUT_STREAM,
|
||||
"output-stream", arrow_writer,
|
||||
NULL);
|
||||
return GARROW_GPU_CUDA_BUFFER_OUTPUT_STREAM(output_stream);
|
||||
}
|
||||
|
||||
std::shared_ptr<arrow::gpu::CudaBufferWriter>
|
||||
garrow_gpu_cuda_buffer_output_stream_get_raw(GArrowGPUCUDABufferOutputStream *output_stream)
|
||||
{
|
||||
if (!output_stream)
|
||||
return nullptr;
|
||||
|
||||
auto arrow_writer =
|
||||
garrow_output_stream_get_raw(GARROW_OUTPUT_STREAM(output_stream));
|
||||
return std::static_pointer_cast<arrow::gpu::CudaBufferWriter>(arrow_writer);
|
||||
}
|
||||
@@ -1,183 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <arrow-glib/arrow-glib.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define GARROW_GPU_TYPE_CUDA_DEVICE_MANAGER \
|
||||
(garrow_gpu_cuda_device_manager_get_type())
|
||||
G_DECLARE_DERIVABLE_TYPE(GArrowGPUCUDADeviceManager,
|
||||
garrow_gpu_cuda_device_manager,
|
||||
GARROW_GPU,
|
||||
CUDA_DEVICE_MANAGER,
|
||||
GObject)
|
||||
struct _GArrowGPUCUDADeviceManagerClass
|
||||
{
|
||||
GObjectClass parent_class;
|
||||
};
|
||||
|
||||
#define GARROW_GPU_TYPE_CUDA_CONTEXT (garrow_gpu_cuda_context_get_type())
|
||||
G_DECLARE_DERIVABLE_TYPE(GArrowGPUCUDAContext,
|
||||
garrow_gpu_cuda_context,
|
||||
GARROW_GPU,
|
||||
CUDA_CONTEXT,
|
||||
GObject)
|
||||
struct _GArrowGPUCUDAContextClass
|
||||
{
|
||||
GObjectClass parent_class;
|
||||
};
|
||||
|
||||
#define GARROW_GPU_TYPE_CUDA_BUFFER (garrow_gpu_cuda_buffer_get_type())
|
||||
G_DECLARE_DERIVABLE_TYPE(GArrowGPUCUDABuffer,
|
||||
garrow_gpu_cuda_buffer,
|
||||
GARROW_GPU,
|
||||
CUDA_BUFFER,
|
||||
GArrowBuffer)
|
||||
struct _GArrowGPUCUDABufferClass
|
||||
{
|
||||
GArrowBufferClass parent_class;
|
||||
};
|
||||
|
||||
#define GARROW_GPU_TYPE_CUDA_HOST_BUFFER (garrow_gpu_cuda_host_buffer_get_type())
|
||||
G_DECLARE_DERIVABLE_TYPE(GArrowGPUCUDAHostBuffer,
|
||||
garrow_gpu_cuda_host_buffer,
|
||||
GARROW_GPU,
|
||||
CUDA_HOST_BUFFER,
|
||||
GArrowMutableBuffer)
|
||||
struct _GArrowGPUCUDAHostBufferClass
|
||||
{
|
||||
GArrowMutableBufferClass parent_class;
|
||||
};
|
||||
|
||||
#define GARROW_GPU_TYPE_CUDA_IPC_MEMORY_HANDLE \
|
||||
(garrow_gpu_cuda_ipc_memory_handle_get_type())
|
||||
G_DECLARE_DERIVABLE_TYPE(GArrowGPUCUDAIPCMemoryHandle,
|
||||
garrow_gpu_cuda_ipc_memory_handle,
|
||||
GARROW_GPU,
|
||||
CUDA_IPC_MEMORY_HANDLE,
|
||||
GObject)
|
||||
struct _GArrowGPUCUDAIPCMemoryHandleClass
|
||||
{
|
||||
GObjectClass parent_class;
|
||||
};
|
||||
|
||||
#define GARROW_GPU_TYPE_CUDA_BUFFER_INPUT_STREAM \
|
||||
(garrow_gpu_cuda_buffer_input_stream_get_type())
|
||||
G_DECLARE_DERIVABLE_TYPE(GArrowGPUCUDABufferInputStream,
|
||||
garrow_gpu_cuda_buffer_input_stream,
|
||||
GARROW_GPU,
|
||||
CUDA_BUFFER_INPUT_STREAM,
|
||||
GArrowBufferInputStream)
|
||||
struct _GArrowGPUCUDABufferInputStreamClass
|
||||
{
|
||||
GArrowBufferInputStreamClass parent_class;
|
||||
};
|
||||
|
||||
#define GARROW_GPU_TYPE_CUDA_BUFFER_OUTPUT_STREAM \
|
||||
(garrow_gpu_cuda_buffer_output_stream_get_type())
|
||||
G_DECLARE_DERIVABLE_TYPE(GArrowGPUCUDABufferOutputStream,
|
||||
garrow_gpu_cuda_buffer_output_stream,
|
||||
GARROW_GPU,
|
||||
CUDA_BUFFER_OUTPUT_STREAM,
|
||||
GArrowOutputStream)
|
||||
struct _GArrowGPUCUDABufferOutputStreamClass
|
||||
{
|
||||
GArrowOutputStreamClass parent_class;
|
||||
};
|
||||
|
||||
GArrowGPUCUDADeviceManager *
|
||||
garrow_gpu_cuda_device_manager_new(GError **error);
|
||||
|
||||
GArrowGPUCUDAContext *
|
||||
garrow_gpu_cuda_device_manager_get_context(GArrowGPUCUDADeviceManager *manager,
|
||||
gint gpu_number,
|
||||
GError **error);
|
||||
gsize
|
||||
garrow_gpu_cuda_device_manager_get_n_devices(GArrowGPUCUDADeviceManager *manager);
|
||||
|
||||
gint64
|
||||
garrow_gpu_cuda_context_get_allocated_size(GArrowGPUCUDAContext *context);
|
||||
|
||||
|
||||
GArrowGPUCUDABuffer *
|
||||
garrow_gpu_cuda_buffer_new(GArrowGPUCUDAContext *context,
|
||||
gint64 size,
|
||||
GError **error);
|
||||
GArrowGPUCUDABuffer *
|
||||
garrow_gpu_cuda_buffer_new_ipc(GArrowGPUCUDAContext *context,
|
||||
GArrowGPUCUDAIPCMemoryHandle *handle,
|
||||
GError **error);
|
||||
GArrowGPUCUDABuffer *
|
||||
garrow_gpu_cuda_buffer_new_record_batch(GArrowGPUCUDAContext *context,
|
||||
GArrowRecordBatch *record_batch,
|
||||
GError **error);
|
||||
GBytes *
|
||||
garrow_gpu_cuda_buffer_copy_to_host(GArrowGPUCUDABuffer *buffer,
|
||||
gint64 position,
|
||||
gint64 size,
|
||||
GError **error);
|
||||
gboolean
|
||||
garrow_gpu_cuda_buffer_copy_from_host(GArrowGPUCUDABuffer *buffer,
|
||||
const guint8 *data,
|
||||
gint64 size,
|
||||
GError **error);
|
||||
GArrowGPUCUDAIPCMemoryHandle *
|
||||
garrow_gpu_cuda_buffer_export(GArrowGPUCUDABuffer *buffer,
|
||||
GError **error);
|
||||
GArrowGPUCUDAContext *
|
||||
garrow_gpu_cuda_buffer_get_context(GArrowGPUCUDABuffer *buffer);
|
||||
GArrowRecordBatch *
|
||||
garrow_gpu_cuda_buffer_read_record_batch(GArrowGPUCUDABuffer *buffer,
|
||||
GArrowSchema *schema,
|
||||
GError **error);
|
||||
|
||||
|
||||
GArrowGPUCUDAHostBuffer *
|
||||
garrow_gpu_cuda_host_buffer_new(gint gpu_number,
|
||||
gint64 size,
|
||||
GError **error);
|
||||
|
||||
GArrowGPUCUDAIPCMemoryHandle *
|
||||
garrow_gpu_cuda_ipc_memory_handle_new(const guint8 *data,
|
||||
gsize size,
|
||||
GError **error);
|
||||
|
||||
GArrowBuffer *
|
||||
garrow_gpu_cuda_ipc_memory_handle_serialize(GArrowGPUCUDAIPCMemoryHandle *handle,
|
||||
GError **error);
|
||||
|
||||
GArrowGPUCUDABufferInputStream *
|
||||
garrow_gpu_cuda_buffer_input_stream_new(GArrowGPUCUDABuffer *buffer);
|
||||
|
||||
GArrowGPUCUDABufferOutputStream *
|
||||
garrow_gpu_cuda_buffer_output_stream_new(GArrowGPUCUDABuffer *buffer);
|
||||
|
||||
gboolean
|
||||
garrow_gpu_cuda_buffer_output_stream_set_buffer_size(GArrowGPUCUDABufferOutputStream *stream,
|
||||
gint64 size,
|
||||
GError **error);
|
||||
gint64
|
||||
garrow_gpu_cuda_buffer_output_stream_get_buffer_size(GArrowGPUCUDABufferOutputStream *stream);
|
||||
gint64
|
||||
garrow_gpu_cuda_buffer_output_stream_get_buffered_size(GArrowGPUCUDABufferOutputStream *stream);
|
||||
|
||||
G_END_DECLS
|
||||
@@ -1,54 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <arrow/gpu/cuda_api.h>
|
||||
|
||||
#include <arrow-gpu-glib/cuda.h>
|
||||
|
||||
GArrowGPUCUDAContext *
|
||||
garrow_gpu_cuda_context_new_raw(std::shared_ptr<arrow::gpu::CudaContext> *arrow_context);
|
||||
std::shared_ptr<arrow::gpu::CudaContext>
|
||||
garrow_gpu_cuda_context_get_raw(GArrowGPUCUDAContext *context);
|
||||
|
||||
GArrowGPUCUDAIPCMemoryHandle *
|
||||
garrow_gpu_cuda_ipc_memory_handle_new_raw(std::shared_ptr<arrow::gpu::CudaIpcMemHandle> *arrow_handle);
|
||||
std::shared_ptr<arrow::gpu::CudaIpcMemHandle>
|
||||
garrow_gpu_cuda_ipc_memory_handle_get_raw(GArrowGPUCUDAIPCMemoryHandle *handle);
|
||||
|
||||
GArrowGPUCUDABuffer *
|
||||
garrow_gpu_cuda_buffer_new_raw(std::shared_ptr<arrow::gpu::CudaBuffer> *arrow_buffer);
|
||||
std::shared_ptr<arrow::gpu::CudaBuffer>
|
||||
garrow_gpu_cuda_buffer_get_raw(GArrowGPUCUDABuffer *buffer);
|
||||
|
||||
GArrowGPUCUDAHostBuffer *
|
||||
garrow_gpu_cuda_host_buffer_new_raw(std::shared_ptr<arrow::gpu::CudaHostBuffer> *arrow_buffer);
|
||||
std::shared_ptr<arrow::gpu::CudaHostBuffer>
|
||||
garrow_gpu_cuda_host_buffer_get_raw(GArrowGPUCUDAHostBuffer *buffer);
|
||||
|
||||
GArrowGPUCUDABufferInputStream *
|
||||
garrow_gpu_cuda_buffer_input_stream_new_raw(std::shared_ptr<arrow::gpu::CudaBufferReader> *arrow_reader);
|
||||
std::shared_ptr<arrow::gpu::CudaBufferReader>
|
||||
garrow_gpu_cuda_buffer_input_stream_get_raw(GArrowGPUCUDABufferInputStream *input_stream);
|
||||
|
||||
GArrowGPUCUDABufferOutputStream *
|
||||
garrow_gpu_cuda_buffer_output_stream_new_raw(std::shared_ptr<arrow::gpu::CudaBufferWriter> *arrow_writer);
|
||||
std::shared_ptr<arrow::gpu::CudaBufferWriter>
|
||||
garrow_gpu_cuda_buffer_output_stream_get_raw(GArrowGPUCUDABufferOutputStream *output_stream);
|
||||
@@ -1,79 +0,0 @@
|
||||
# -*- indent-tabs-mode: nil -*-
|
||||
#
|
||||
# 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.
|
||||
|
||||
sources = files(
|
||||
'cuda.cpp',
|
||||
)
|
||||
|
||||
c_headers = files(
|
||||
'arrow-gpu-glib.h',
|
||||
'cuda.h',
|
||||
)
|
||||
|
||||
cpp_headers = files(
|
||||
'arrow-gpu-glib.hpp',
|
||||
'cuda.hpp',
|
||||
)
|
||||
|
||||
headers = c_headers + cpp_headers
|
||||
install_headers(headers, subdir: 'arrow-gpu-glib')
|
||||
|
||||
|
||||
dependencies = [
|
||||
arrow_gpu,
|
||||
arrow_glib,
|
||||
]
|
||||
libarrow_gpu_glib = library('arrow-gpu-glib',
|
||||
sources: sources,
|
||||
install: true,
|
||||
dependencies: dependencies,
|
||||
include_directories: base_include_directories,
|
||||
soversion: so_version,
|
||||
version: library_version)
|
||||
arrow_gpu_glib = declare_dependency(link_with: libarrow_gpu_glib,
|
||||
include_directories: base_include_directories,
|
||||
dependencies: dependencies)
|
||||
|
||||
pkgconfig.generate(filebase: 'arrow-gpu-glib',
|
||||
name: 'Apache Arrow GPU GLib',
|
||||
description: 'C API for Apache Arrow GPU based on GLib',
|
||||
version: version,
|
||||
requires: ['arrow-glib', 'arrow-gpu'],
|
||||
libraries: [libarrow_gpu_glib])
|
||||
|
||||
gir_dependencies = [
|
||||
declare_dependency(sources: arrow_glib_gir),
|
||||
]
|
||||
gir_extra_args = [
|
||||
'--warn-all',
|
||||
'--include-uninstalled=./arrow-glib/Arrow-1.0.gir',
|
||||
]
|
||||
arrow_gpu_glib_gir = gnome.generate_gir(libarrow_gpu_glib,
|
||||
dependencies: gir_dependencies,
|
||||
sources: sources + c_headers,
|
||||
namespace: 'ArrowGPU',
|
||||
nsversion: api_version,
|
||||
identifier_prefix: 'GArrowGPU',
|
||||
symbol_prefix: 'garrow_gpu',
|
||||
export_packages: 'arrow-gpu-glib',
|
||||
includes: [
|
||||
'Arrow-1.0',
|
||||
],
|
||||
install: true,
|
||||
extra_args: gir_extra_args)
|
||||
+20
-20
@@ -130,10 +130,10 @@ if test "x$GARROW_ARROW_CPP_BUILD_DIR" = "x"; then
|
||||
[arrow-orc],
|
||||
[HAVE_ARROW_ORC=yes],
|
||||
[HAVE_ARROW_ORC=no])
|
||||
PKG_CHECK_MODULES([ARROW_GPU],
|
||||
[arrow-gpu],
|
||||
[HAVE_ARROW_GPU=yes],
|
||||
[HAVE_ARROW_GPU=no])
|
||||
PKG_CHECK_MODULES([ARROW_CUDA],
|
||||
[arrow-cuda],
|
||||
[HAVE_ARROW_CUDA=yes],
|
||||
[HAVE_ARROW_CUDA=no])
|
||||
PKG_CHECK_MODULES([GANDIVA],
|
||||
[gandiva],
|
||||
[HAVE_GANDIVA=yes],
|
||||
@@ -168,16 +168,16 @@ else
|
||||
HAVE_ARROW_ORC=no
|
||||
fi
|
||||
|
||||
ARROW_GPU_CFLAGS=""
|
||||
if test -f "${GARROW_ARROW_CPP_BUILD_DIR}/src/arrow/gpu/arrow-gpu.pc"; then
|
||||
HAVE_ARROW_GPU=yes
|
||||
ARROW_GPU_LIBS="-larrow_gpu"
|
||||
ARROW_CUDA_CFLAGS=""
|
||||
if test -f "${GARROW_ARROW_CPP_BUILD_DIR}/src/arrow/cuda/arrow-cuda.pc"; then
|
||||
HAVE_ARROW_CUDA=yes
|
||||
ARROW_CUDA_LIBS="-larrow_cuda"
|
||||
else
|
||||
HAVE_ARROW_GPU=no
|
||||
ARROW_GPU_LIBS=""
|
||||
HAVE_ARROW_CUDA=no
|
||||
ARROW_CUDA_LIBS=""
|
||||
fi
|
||||
AC_SUBST(ARROW_GPU_CFLAGS)
|
||||
AC_SUBST(ARROW_GPU_LIBS)
|
||||
AC_SUBST(ARROW_CUDA_CFLAGS)
|
||||
AC_SUBST(ARROW_CUDA_LIBS)
|
||||
|
||||
GANDIVA_CFLAGS=""
|
||||
if test -f "${GARROW_ARROW_CPP_BUILD_DIR}/src/gandiva/gandiva.pc"; then
|
||||
@@ -221,14 +221,14 @@ if test "$HAVE_ARROW_ORC" = "yes"; then
|
||||
AC_DEFINE(HAVE_ARROW_ORC, [1], [Define to 1 if Apache Arrow supports ORC.])
|
||||
fi
|
||||
|
||||
AM_CONDITIONAL([HAVE_ARROW_GPU], [test "$HAVE_ARROW_GPU" = "yes"])
|
||||
if test "$HAVE_ARROW_GPU" = "yes"; then
|
||||
ARROW_GPU_GLIB_PACKAGE="arrow-gpu-glib"
|
||||
AC_DEFINE(HAVE_ARROW_GPU, [1], [Define to 1 if Apache Arrow supports GPU.])
|
||||
AM_CONDITIONAL([HAVE_ARROW_CUDA], [test "$HAVE_ARROW_CUDA" = "yes"])
|
||||
if test "$HAVE_ARROW_CUDA" = "yes"; then
|
||||
ARROW_CUDA_GLIB_PACKAGE="arrow-cuda-glib"
|
||||
AC_DEFINE(HAVE_ARROW_CUDA, [1], [Define to 1 if Apache Arrow supports CUDA.])
|
||||
else
|
||||
ARROW_GPU_GLIB_PACKAGE=""
|
||||
ARROW_CUDA_GLIB_PACKAGE=""
|
||||
fi
|
||||
AC_SUBST(ARROW_GPU_GLIB_PACKAGE)
|
||||
AC_SUBST(ARROW_CUDA_GLIB_PACKAGE)
|
||||
|
||||
AM_CONDITIONAL([HAVE_GANDIVA], [test "$HAVE_GANDIVA" = "yes"])
|
||||
if test "$HAVE_GANDIVA" = "yes"; then
|
||||
@@ -250,12 +250,12 @@ AC_SUBST(exampledir)
|
||||
|
||||
AC_CONFIG_FILES([
|
||||
Makefile
|
||||
arrow-cuda-glib/Makefile
|
||||
arrow-cuda-glib/arrow-cuda-glib.pc
|
||||
arrow-glib/Makefile
|
||||
arrow-glib/arrow-glib.pc
|
||||
arrow-glib/arrow-orc-glib.pc
|
||||
arrow-glib/version.h
|
||||
arrow-gpu-glib/Makefile
|
||||
arrow-gpu-glib/arrow-gpu-glib.pc
|
||||
gandiva-glib/Makefile
|
||||
gandiva-glib/gandiva-glib.pc
|
||||
parquet-glib/Makefile
|
||||
|
||||
@@ -55,15 +55,15 @@ AM_CFLAGS = \
|
||||
GTKDOC_LIBS = \
|
||||
$(top_builddir)/arrow-glib/libarrow-glib.la
|
||||
|
||||
if HAVE_ARROW_GPU
|
||||
if HAVE_ARROW_CUDA
|
||||
DOC_SOURCE_DIR += \
|
||||
$(top_srcdir)/arrow-gpu-glib
|
||||
$(top_srcdir)/arrow-cuda-glib
|
||||
HFILE_GLOB += \
|
||||
$(top_srcdir)/arrow-gpu-glib/*.h
|
||||
$(top_srcdir)/arrow-cuda-glib/*.h
|
||||
CFILE_GLOB += \
|
||||
$(top_srcdir)/arrow-gpu-glib/*.cpp
|
||||
$(top_srcdir)/arrow-cuda-glib/*.cpp
|
||||
GTKDOC_LIBS += \
|
||||
$(top_builddir)/arrow-gpu-glib/libarrow-gpu-glib.la
|
||||
$(top_builddir)/arrow-cuda-glib/libarrow-cuda-glib.la
|
||||
endif
|
||||
|
||||
include $(top_srcdir)/gtk-doc.make
|
||||
|
||||
@@ -50,13 +50,13 @@ source_directories = [
|
||||
dependencies = [
|
||||
arrow_glib,
|
||||
]
|
||||
if arrow_gpu.found()
|
||||
if arrow_cuda.found()
|
||||
source_directories += [
|
||||
join_paths(meson.source_root(), 'arrow-gpu-glib'),
|
||||
join_paths(meson.build_root(), 'arrow-gpu-glib'),
|
||||
join_paths(meson.source_root(), 'arrow-cuda-glib'),
|
||||
join_paths(meson.build_root(), 'arrow-cuda-glib'),
|
||||
]
|
||||
dependencies += [
|
||||
arrow_gpu_glib,
|
||||
arrow_cuda_glib,
|
||||
]
|
||||
endif
|
||||
ignore_headers = []
|
||||
|
||||
@@ -15,10 +15,10 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
PLASMA_ARROW_GPU_GTKDOC_LIBS =
|
||||
if HAVE_ARROW_GPU
|
||||
PLASMA_ARROW_GPU_GTKDOC_LIBS += \
|
||||
$(top_builddir)/arrow-gpu-glib/libarrow-gpu-glib.la
|
||||
PLASMA_ARROW_CUDA_GTKDOC_LIBS =
|
||||
if HAVE_ARROW_CUDA
|
||||
PLASMA_ARROW_CUDA_GTKDOC_LIBS += \
|
||||
$(top_builddir)/arrow-cuda-glib/libarrow-cuda-glib.la
|
||||
endif
|
||||
|
||||
if HAVE_PLASMA
|
||||
@@ -56,7 +56,7 @@ AM_CFLAGS = \
|
||||
|
||||
GTKDOC_LIBS = \
|
||||
$(top_builddir)/arrow-glib/libarrow-glib.la \
|
||||
$(PLASMA_ARROW_GPU_GTKDOC_LIBS) \
|
||||
$(PLASMA_ARROW_CUDA_GTKDOC_LIBS) \
|
||||
$(top_builddir)/plasma-glib/libplasma-glib.la
|
||||
|
||||
include $(top_srcdir)/gtk-doc.make
|
||||
|
||||
@@ -56,8 +56,8 @@ dependencies = [
|
||||
arrow_glib,
|
||||
plasma_glib,
|
||||
]
|
||||
if arrow_gpu.found()
|
||||
dependencies += [arrow_gpu_glib]
|
||||
if arrow_cuda.found()
|
||||
dependencies += [arrow_cuda_glib]
|
||||
endif
|
||||
ignore_headers = []
|
||||
gnome.gtkdoc(project_name,
|
||||
|
||||
+7
-7
@@ -64,7 +64,7 @@ endif
|
||||
if arrow_cpp_build_lib_dir == ''
|
||||
arrow = dependency('arrow')
|
||||
have_arrow_orc = dependency('arrow-orc', required: false).found()
|
||||
arrow_gpu = dependency('arrow-gpu', required: false)
|
||||
arrow_cuda = dependency('arrow-cuda', required: false)
|
||||
gandiva = dependency('gandiva', required: false)
|
||||
parquet = dependency('parquet', required: false)
|
||||
plasma = dependency('plasma', required: false)
|
||||
@@ -89,9 +89,9 @@ main(void)
|
||||
have_arrow_orc = cpp_compiler.links(arrow_orc_code,
|
||||
include_directories: base_include_directories,
|
||||
dependencies: [arrow])
|
||||
arrow_gpu = cpp_compiler.find_library('arrow_gpu',
|
||||
dirs: [arrow_cpp_build_lib_dir],
|
||||
required: false)
|
||||
arrow_cuda = cpp_compiler.find_library('arrow_cuda',
|
||||
dirs: [arrow_cpp_build_lib_dir],
|
||||
required: false)
|
||||
gandiva = cpp_compiler.find_library('gandiva',
|
||||
dirs: [arrow_cpp_build_lib_dir],
|
||||
required: false)
|
||||
@@ -104,8 +104,8 @@ main(void)
|
||||
endif
|
||||
|
||||
subdir('arrow-glib')
|
||||
if arrow_gpu.found()
|
||||
subdir('arrow-gpu-glib')
|
||||
if arrow_cuda.found()
|
||||
subdir('arrow-cuda-glib')
|
||||
endif
|
||||
if gandiva.found()
|
||||
subdir('gandiva-glib')
|
||||
@@ -136,7 +136,7 @@ test('unit test',
|
||||
run_test,
|
||||
env: [
|
||||
'ARROW_GLIB_TYPELIB_DIR=@0@/arrow-glib'.format(meson.build_root()),
|
||||
'ARROW_GPU_GLIB_TYPELIB_DIR=@0@/arrow-gpu-glib'.format(meson.build_root()),
|
||||
'ARROW_CUDA_GLIB_TYPELIB_DIR=@0@/arrow-cuda-glib'.format(meson.build_root()),
|
||||
'GANDIVA_GLIB_TYPELIB_DIR=@0@/gandiva-glib'.format(meson.build_root()),
|
||||
'PARQUET_GLIB_TYPELIB_DIR=@0@/parquet-glib'.format(meson.build_root()),
|
||||
'PARQUET_GLIB_TYPELIB_DIR=@0@/plasma-glib'.format(meson.build_root()),
|
||||
|
||||
@@ -31,32 +31,32 @@ AM_CFLAGS = \
|
||||
$(GARROW_CFLAGS) \
|
||||
$(GPLASMA_CFLAGS)
|
||||
|
||||
PLASMA_ARROW_GPU_LIBS =
|
||||
PLASMA_ARROW_GPU_GLIB_PKG_CONFIG_PATH =
|
||||
PLASMA_INTROSPECTION_COMPILER_ARROW_GPU_ARGS =
|
||||
PLASMA_GIR_ARROW_GPU_PACKAGE =
|
||||
PLASMA_GIR_ARROW_GPU_SCANNER_ADD_INCLUDE_PATH =
|
||||
PLASMA_GIR_ARROW_GPU_LIBS_MACOS =
|
||||
PLASMA_GIR_ARROW_GPU_SCANNER_LIBRARY_PATH_MACOS =
|
||||
PLASMA_GIR_ARROW_GPU_LIBS =
|
||||
if HAVE_ARROW_GPU
|
||||
PLASMA_ARROW_GPU_LIBS += \
|
||||
$(ARROW_GPU_LIBS) \
|
||||
../arrow-gpu-glib/libarrow-gpu-glib.la
|
||||
PLASMA_ARROW_GPU_GLIB_PKG_CONFIG_PATH += \
|
||||
:${abs_top_builddir}/arrow-gpu-glib
|
||||
PLASMA_INTROSPECTION_COMPILER_ARROW_GPU_ARGS += \
|
||||
--includedir=$(abs_top_builddir)/arrow-gpu-glib
|
||||
PLASMA_GIR_ARROW_GPU_PACKAGE += \
|
||||
arrow-gpu-glib
|
||||
PLASMA_GIR_ARROW_GPU_SCANNER_ADD_INCLUDE_PATH += \
|
||||
--add-include-path=$(abs_top_builddir)/arrow-gpu-glib
|
||||
PLASMA_GIR_ARROW_GPU_LIBS_MACOS += \
|
||||
arrow-gpu-glib
|
||||
PLASMA_GIR_ARROW_GPU_SCANNER_LIBRARY_PATH_MACOS += \
|
||||
--library-path=$(abs_top_builddir)/arrow-gpu-glib/.libs
|
||||
PLASMA_GIR_ARROW_GPU_LIBS += \
|
||||
$(abs_top_builddir)/arrow-gpu-glib/libarrow-gpu-glib.la
|
||||
PLASMA_ARROW_CUDA_LIBS =
|
||||
PLASMA_ARROW_CUDA_GLIB_PKG_CONFIG_PATH =
|
||||
PLASMA_INTROSPECTION_COMPILER_ARROW_CUDA_ARGS =
|
||||
PLASMA_GIR_ARROW_CUDA_PACKAGE =
|
||||
PLASMA_GIR_ARROW_CUDA_SCANNER_ADD_INCLUDE_PATH =
|
||||
PLASMA_GIR_ARROW_CUDA_LIBS_MACOS =
|
||||
PLASMA_GIR_ARROW_CUDA_SCANNER_LIBRARY_PATH_MACOS =
|
||||
PLASMA_GIR_ARROW_CUDA_LIBS =
|
||||
if HAVE_ARROW_CUDA
|
||||
PLASMA_ARROW_CUDA_LIBS += \
|
||||
$(ARROW_CUDA_LIBS) \
|
||||
../arrow-cuda-glib/libarrow-cuda-glib.la
|
||||
PLASMA_ARROW_CUDA_GLIB_PKG_CONFIG_PATH += \
|
||||
:${abs_top_builddir}/arrow-cuda-glib
|
||||
PLASMA_INTROSPECTION_COMPILER_ARROW_CUDA_ARGS += \
|
||||
--includedir=$(abs_top_builddir)/arrow-cuda-glib
|
||||
PLASMA_GIR_ARROW_CUDA_PACKAGE += \
|
||||
arrow-cuda-glib
|
||||
PLASMA_GIR_ARROW_CUDA_SCANNER_ADD_INCLUDE_PATH += \
|
||||
--add-include-path=$(abs_top_builddir)/arrow-cuda-glib
|
||||
PLASMA_GIR_ARROW_CUDA_LIBS_MACOS += \
|
||||
arrow-cuda-glib
|
||||
PLASMA_GIR_ARROW_CUDA_SCANNER_LIBRARY_PATH_MACOS += \
|
||||
--library-path=$(abs_top_builddir)/arrow-cuda-glib/.libs
|
||||
PLASMA_GIR_ARROW_CUDA_LIBS += \
|
||||
$(abs_top_builddir)/arrow-cuda-glib/libarrow-cuda-glib.la
|
||||
endif
|
||||
|
||||
if HAVE_PLASMA
|
||||
@@ -79,7 +79,7 @@ libplasma_glib_la_LIBADD = \
|
||||
$(ARROW_LIBS) \
|
||||
$(PLASMA_LIBS) \
|
||||
../arrow-glib/libarrow-glib.la \
|
||||
$(PLASMA_ARROW_GPU_LIBS)
|
||||
$(PLASMA_ARROW_CUDA_LIBS)
|
||||
|
||||
libplasma_glib_la_headers = \
|
||||
client.h \
|
||||
@@ -117,19 +117,19 @@ INTROSPECTION_SCANNER_ARGS =
|
||||
INTROSPECTION_SCANNER_ENV =
|
||||
if USE_ARROW_BUILD_DIR
|
||||
INTROSPECTION_SCANNER_ENV += \
|
||||
PKG_CONFIG_PATH=${abs_top_builddir}/arrow-glib$(PLASMA_ARROW_GPU_GLIB_PKG_CONFIG_PATH):$(ARROW_BUILD_DIR)/src/arrow:$${PKG_CONFIG_PATH}
|
||||
PKG_CONFIG_PATH=${abs_top_builddir}/arrow-glib$(PLASMA_ARROW_CUDA_GLIB_PKG_CONFIG_PATH):$(ARROW_BUILD_DIR)/src/arrow:$${PKG_CONFIG_PATH}
|
||||
else
|
||||
INTROSPECTION_SCANNER_ENV += \
|
||||
PKG_CONFIG_PATH=${abs_top_builddir}/arrow-glib$(PLASMA_ARROW_GPU_GLIB_PKG_CONFIG_PATH):$${PKG_CONFIG_PATH}
|
||||
PKG_CONFIG_PATH=${abs_top_builddir}/arrow-glib$(PLASMA_ARROW_CUDA_GLIB_PKG_CONFIG_PATH):$${PKG_CONFIG_PATH}
|
||||
endif
|
||||
INTROSPECTION_COMPILER_ARGS = \
|
||||
--includedir=$(abs_top_builddir)/arrow-glib \
|
||||
$(PLASMA_INTROSPECTION_COMPILER_ARROW_GPU_INCLUDEDIR)
|
||||
$(PLASMA_INTROSPECTION_COMPILER_ARROW_CUDA_INCLUDEDIR)
|
||||
|
||||
Plasma-1.0.gir: libplasma-glib.la
|
||||
Plasma_1_0_gir_PACKAGES = \
|
||||
arrow-glib \
|
||||
$(PLASMA_GIR_ARROW_GPU_PACKAGE)
|
||||
$(PLASMA_GIR_ARROW_CUDA_PACKAGE)
|
||||
Plasma_1_0_gir_EXPORT_PACKAGES = \
|
||||
plasma-glib
|
||||
Plasma_1_0_gir_INCLUDES = \
|
||||
@@ -140,7 +140,7 @@ Plasma_1_0_gir_LIBS =
|
||||
Plasma_1_0_gir_FILES = $(libplasma_glib_la_sources)
|
||||
Plasma_1_0_gir_SCANNERFLAGS = \
|
||||
--add-include-path=$(abs_top_builddir)/arrow-glib \
|
||||
$(PLASMA_GIR_ARROW_GPU_SCANNER_ADD_INCLUDE_PATH) \
|
||||
$(PLASMA_GIR_ARROW_CUDA_SCANNER_ADD_INCLUDE_PATH) \
|
||||
--library-path=$(ARROW_LIB_DIR) \
|
||||
--warn-all \
|
||||
--identifier-prefix=GPlasma \
|
||||
@@ -148,17 +148,17 @@ Plasma_1_0_gir_SCANNERFLAGS = \
|
||||
if OS_MACOS
|
||||
Plasma_1_0_gir_LIBS += \
|
||||
arrow-glib \
|
||||
$(PLASMA_GIR_ARROW_GPU_LIBS_MACOS) \
|
||||
$(PLASMA_GIR_ARROW_CUDA_LIBS_MACOS) \
|
||||
plasma-glib
|
||||
Plasma_1_0_gir_SCANNERFLAGS += \
|
||||
--no-libtool \
|
||||
--library-path=$(abs_top_builddir)/arrow-glib/.libs \
|
||||
$(PLASMA_GIR_ARROW_GPU_SCANNER_LIBRARY_PATH_MACOS) \
|
||||
$(PLASMA_GIR_ARROW_CUDA_SCANNER_LIBRARY_PATH_MACOS) \
|
||||
--library-path=$(abs_builddir)/.libs
|
||||
else
|
||||
Plasma_1_0_gir_LIBS += \
|
||||
$(abs_top_builddir)/arrow-glib/libarrow-glib.la \
|
||||
$(PLASMA_GIR_ARROW_GPU_LIBS) \
|
||||
$(PLASMA_GIR_ARROW_CUDA_LIBS) \
|
||||
libplasma-glib.la
|
||||
endif
|
||||
INTROSPECTION_GIRS += Plasma-1.0.gir
|
||||
|
||||
@@ -24,8 +24,8 @@
|
||||
#include <arrow-glib/buffer.hpp>
|
||||
#include <arrow-glib/error.hpp>
|
||||
|
||||
#ifdef HAVE_ARROW_GPU
|
||||
# include <arrow-gpu-glib/cuda.hpp>
|
||||
#ifdef HAVE_ARROW_CUDA
|
||||
# include <arrow-cuda-glib/cuda.hpp>
|
||||
#endif
|
||||
|
||||
#include <plasma-glib/client.hpp>
|
||||
@@ -311,11 +311,11 @@ gplasma_client_create(GPlasmaClient *client,
|
||||
raw_metadata = options_priv->metadata;
|
||||
raw_metadata_size = options_priv->metadata_size;
|
||||
if (options_priv->gpu_device >= 0) {
|
||||
#ifndef HAVE_ARROW_GPU
|
||||
#ifndef HAVE_ARROW_CUDA
|
||||
g_set_error(error,
|
||||
GARROW_ERROR,
|
||||
GARROW_ERROR_INVALID,
|
||||
"%s Arrow GPU GLib is needed to use GPU",
|
||||
"%s Arrow CUDA GLib is needed to use GPU",
|
||||
context);
|
||||
return NULL;
|
||||
#endif
|
||||
@@ -335,11 +335,11 @@ gplasma_client_create(GPlasmaClient *client,
|
||||
auto plasma_mutable_data =
|
||||
std::static_pointer_cast<arrow::MutableBuffer>(plasma_data);
|
||||
data = GARROW_BUFFER(garrow_mutable_buffer_new_raw(&plasma_mutable_data));
|
||||
#ifdef HAVE_ARROW_GPU
|
||||
#ifdef HAVE_ARROW_CUDA
|
||||
} else {
|
||||
auto plasma_cuda_data =
|
||||
std::static_pointer_cast<arrow::gpu::CudaBuffer>(plasma_data);
|
||||
data = GARROW_BUFFER(garrow_gpu_cuda_buffer_new_raw(&plasma_cuda_data));
|
||||
std::static_pointer_cast<arrow::cuda::CudaBuffer>(plasma_data);
|
||||
data = GARROW_BUFFER(garrow_cuda_buffer_new_raw(&plasma_cuda_data));
|
||||
#endif
|
||||
}
|
||||
GArrowBuffer *metadata = nullptr;
|
||||
@@ -392,28 +392,28 @@ gplasma_client_refer_object(GPlasmaClient *client,
|
||||
GArrowBuffer *data = nullptr;
|
||||
GArrowBuffer *metadata = nullptr;
|
||||
if (plasma_object_buffer.device_num > 0) {
|
||||
#ifdef HAVE_ARROW_GPU
|
||||
std::shared_ptr<arrow::gpu::CudaBuffer> plasma_cuda_data;
|
||||
status = arrow::gpu::CudaBuffer::FromBuffer(plasma_data,
|
||||
&plasma_cuda_data);
|
||||
#ifdef HAVE_ARROW_CUDA
|
||||
std::shared_ptr<arrow::cuda::CudaBuffer> plasma_cuda_data;
|
||||
status = arrow::cuda::CudaBuffer::FromBuffer(plasma_data,
|
||||
&plasma_cuda_data);
|
||||
if (!garrow_error_check(error, status, context)) {
|
||||
return NULL;
|
||||
}
|
||||
std::shared_ptr<arrow::gpu::CudaBuffer> plasma_cuda_metadata;
|
||||
status = arrow::gpu::CudaBuffer::FromBuffer(plasma_metadata,
|
||||
std::shared_ptr<arrow::cuda::CudaBuffer> plasma_cuda_metadata;
|
||||
status = arrow::cuda::CudaBuffer::FromBuffer(plasma_metadata,
|
||||
&plasma_cuda_metadata);
|
||||
if (!garrow_error_check(error, status, context)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
data = GARROW_BUFFER(garrow_gpu_cuda_buffer_new_raw(&plasma_cuda_data));
|
||||
data = GARROW_BUFFER(garrow_cuda_buffer_new_raw(&plasma_cuda_data));
|
||||
metadata =
|
||||
GARROW_BUFFER(garrow_gpu_cuda_buffer_new_raw(&plasma_cuda_metadata));
|
||||
GARROW_BUFFER(garrow_cuda_buffer_new_raw(&plasma_cuda_metadata));
|
||||
#else
|
||||
g_set_error(error,
|
||||
GARROW_ERROR,
|
||||
GARROW_ERROR_INVALID,
|
||||
"%s Arrow GPU GLib is needed to use GPU",
|
||||
"%s Arrow CUDA GLib is needed to use GPU",
|
||||
context);
|
||||
return NULL;
|
||||
#endif
|
||||
|
||||
@@ -61,13 +61,13 @@ gir_extra_args = [
|
||||
'--warn-all',
|
||||
'--include-uninstalled=./arrow-glib/Arrow-1.0.gir',
|
||||
]
|
||||
if arrow_gpu.found()
|
||||
dependencies += [arrow_gpu_glib]
|
||||
cpp_args += ['-DHAVE_ARROW_GPU']
|
||||
pkg_config_requires += ['arrow-gpu-glib']
|
||||
gir_dependencies += [declare_dependency(sources: arrow_gpu_glib_gir)]
|
||||
gir_includes += ['ArrowGPU-1.0']
|
||||
gir_extra_args += ['--include-uninstalled=./arrow-gpu-glib/ArrowGPU-1.0.gir']
|
||||
if arrow_cuda.found()
|
||||
dependencies += [arrow_cuda_glib]
|
||||
cpp_args += ['-DHAVE_ARROW_CUDA']
|
||||
pkg_config_requires += ['arrow-cuda-glib']
|
||||
gir_dependencies += [declare_dependency(sources: arrow_cuda_glib_gir)]
|
||||
gir_includes += ['ArrowCUDA-1.0']
|
||||
gir_extra_args += ['--include-uninstalled=./arrow-cuda-glib/ArrowCUDA-1.0.gir']
|
||||
endif
|
||||
libplasma_glib = library('plasma-glib',
|
||||
sources: sources,
|
||||
|
||||
@@ -61,7 +61,7 @@ class TestPlasmaClient < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
test("options: GPU device") do
|
||||
omit("Arrow GPU is required") unless defined?(::ArrowGPU)
|
||||
omit("Arrow CUDA is required") unless defined?(::ArrowCUDA)
|
||||
|
||||
gpu_device = 0
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ module Arrow
|
||||
end
|
||||
|
||||
begin
|
||||
ArrowGPU = GI.load("ArrowGPU")
|
||||
ArrowCUDA = GI.load("ArrowCUDA")
|
||||
rescue GObjectIntrospection::RepositoryError::TypelibNotFound
|
||||
end
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
test_dir="$(cd $(dirname $0); pwd)"
|
||||
build_dir="$(cd .; pwd)"
|
||||
|
||||
modules="arrow-glib arrow-gpu-glib gandiva-glib parquet-glib plasma-glib"
|
||||
modules="arrow-glib arrow-cuda-glib gandiva-glib parquet-glib plasma-glib"
|
||||
|
||||
for module in ${modules}; do
|
||||
module_build_dir="${build_dir}/${module}"
|
||||
|
||||
@@ -15,12 +15,12 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
class TestGPUCUDA < Test::Unit::TestCase
|
||||
class TestCUDA < Test::Unit::TestCase
|
||||
include Helper::Buildable
|
||||
|
||||
def setup
|
||||
omit("Arrow GPU is required") unless defined?(::ArrowGPU)
|
||||
@manager = ArrowGPU::CUDADeviceManager.new
|
||||
omit("Arrow CUDA is required") unless defined?(::ArrowCUDA)
|
||||
@manager = ArrowCUDA::DeviceManager.new
|
||||
omit("At least one GPU is required") if @manager.n_devices.zero?
|
||||
@context = @manager.get_context(0)
|
||||
end
|
||||
@@ -29,7 +29,7 @@ class TestGPUCUDA < Test::Unit::TestCase
|
||||
def test_allocated_size
|
||||
allocated_size_before = @context.allocated_size
|
||||
size = 128
|
||||
buffer = ArrowGPU::CUDABuffer.new(@context, size)
|
||||
buffer = ArrowCUDA::Buffer.new(@context, size)
|
||||
assert_equal(size,
|
||||
@context.allocated_size - allocated_size_before)
|
||||
end
|
||||
@@ -38,7 +38,7 @@ class TestGPUCUDA < Test::Unit::TestCase
|
||||
sub_test_case("Buffer") do
|
||||
def setup
|
||||
super
|
||||
@buffer = ArrowGPU::CUDABuffer.new(@context, 128)
|
||||
@buffer = ArrowCUDA::Buffer.new(@context, 128)
|
||||
end
|
||||
|
||||
def test_copy
|
||||
@@ -50,19 +50,19 @@ class TestGPUCUDA < Test::Unit::TestCase
|
||||
@buffer.copy_from_host("Hello World")
|
||||
handle = @buffer.export
|
||||
serialized_handle = handle.serialize.data
|
||||
Tempfile.open("arrow-gpu-cuda-export") do |output|
|
||||
Tempfile.open("arrow-cuda-export") do |output|
|
||||
pid = spawn(RbConfig.ruby, "-e", <<-SCRIPT)
|
||||
require "gi"
|
||||
|
||||
Gio = GI.load("Gio")
|
||||
Arrow = GI.load("Arrow")
|
||||
ArrowGPU = GI.load("ArrowGPU")
|
||||
ArrowCUDA = GI.load("ArrowCUDA")
|
||||
|
||||
manager = ArrowGPU::CUDADeviceManager.new
|
||||
manager = ArrowCUDA::ADeviceManager.new
|
||||
context = manager.get_context(0)
|
||||
serialized_handle = #{serialized_handle.to_s.dump}
|
||||
handle = ArrowGPU::CUDAIPCMemoryHandle.new(serialized_handle)
|
||||
buffer = ArrowGPU::CUDABuffer.new(context, handle)
|
||||
handle = ArrowCUDA::IPCMemoryHandle.new(serialized_handle)
|
||||
buffer = ArrowCUDA::Buffer.new(context, handle)
|
||||
File.open(#{output.path.dump}, "w") do |output|
|
||||
output.print(buffer.copy_to_host(0, 6).to_s)
|
||||
end
|
||||
@@ -85,7 +85,7 @@ end
|
||||
]
|
||||
cpu_record_batch = Arrow::RecordBatch.new(schema, 1, columns)
|
||||
|
||||
buffer = ArrowGPU::CUDABuffer.new(@context, cpu_record_batch)
|
||||
buffer = ArrowCUDA::Buffer.new(@context, cpu_record_batch)
|
||||
gpu_record_batch = buffer.read_record_batch(schema)
|
||||
assert_equal(cpu_record_batch.n_rows,
|
||||
gpu_record_batch.n_rows)
|
||||
@@ -94,16 +94,16 @@ end
|
||||
|
||||
sub_test_case("HostBuffer") do
|
||||
def test_new
|
||||
buffer = ArrowGPU::CUDAHostBuffer.new(0, 128)
|
||||
buffer = ArrowCUDA::HostBuffer.new(0, 128)
|
||||
assert_equal(128, buffer.size)
|
||||
end
|
||||
end
|
||||
|
||||
sub_test_case("BufferInputStream") do
|
||||
def test_new
|
||||
buffer = ArrowGPU::CUDABuffer.new(@context, 128)
|
||||
buffer = ArrowCUDA::Buffer.new(@context, 128)
|
||||
buffer.copy_from_host("Hello World")
|
||||
stream = ArrowGPU::CUDABufferInputStream.new(buffer)
|
||||
stream = ArrowCUDA::BufferInputStream.new(buffer)
|
||||
begin
|
||||
assert_equal("Hello Worl", stream.read(5).copy_to_host(0, 10).to_s)
|
||||
ensure
|
||||
@@ -115,9 +115,9 @@ end
|
||||
sub_test_case("BufferOutputStream") do
|
||||
def setup
|
||||
super
|
||||
@buffer = ArrowGPU::CUDABuffer.new(@context, 128)
|
||||
@buffer = ArrowCUDA::Buffer.new(@context, 128)
|
||||
@buffer.copy_from_host("\x00" * @buffer.size)
|
||||
@stream = ArrowGPU::CUDABufferOutputStream.new(@buffer)
|
||||
@stream = ArrowCUDA::BufferOutputStream.new(@buffer)
|
||||
end
|
||||
|
||||
def cleanup
|
||||
Reference in new issue
Block a user