Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion c_glib/arrow-glib/input-stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ namespace garrow {
}
}

arrow::Status Tell(int64_t *position) override {
arrow::Status Tell(int64_t *position) const override {
if (!G_IS_SEEKABLE(input_stream_)) {
std::string message("[gio-input-stream][tell] "
"not seekable input stream: <");
Expand Down
2 changes: 1 addition & 1 deletion c_glib/arrow-glib/output-stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ namespace garrow {
}
}

arrow::Status Tell(int64_t *position) override {
arrow::Status Tell(int64_t *position) const override {
if (!G_IS_SEEKABLE(output_stream_)) {
std::string message("[gio-output-stream][tell] "
"not seekable output stream: <");
Expand Down
19 changes: 15 additions & 4 deletions cpp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,27 @@ all of these variables. Note that `ARROW_BUILD_TOOLCHAIN` will not set
`BOOST_ROOT`, so if you have custom Boost installation, you must set this
environment variable separately.

### Building Python integration library
### Building Python integration library (optional)

The `arrow_python` shared library can be built by passing `-DARROW_PYTHON=on`
to CMake. This must be installed or in your library load path to be able to
build pyarrow, the Arrow Python bindings.
The optional `arrow_python` shared library can be built by passing
`-DARROW_PYTHON=on` to CMake. This must be installed or in your library load
path to be able to build pyarrow, the Arrow Python bindings.

The Python library must be built against the same Python version for which you
are building pyarrow, e.g. Python 2.7 or Python 3.6. NumPy must also be
installed.

### Building GPU extension library (optional)

The optional `arrow_gpu` shared library can be built by passing
`-DARROW_GPU=on`. This requires a CUDA installation to build, and to use many
of the functions you must have a functioning GPU. Currently only CUDA
functionality is supported, though if there is demand we can also add OpenCL
interfaces in this library as needed.

The CUDA toolchain used to build the library can be customized by using the
`$CUDA_HOME` environment variable.

### API documentation

To generate the (html) API documentation, run the following command in the apidoc
Expand Down
2 changes: 1 addition & 1 deletion cpp/apidoc/Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -2084,7 +2084,7 @@ PREDEFINED = __attribute__(x)= \
# definition found in the source code.
# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.

EXPAND_AS_DEFINED = ARROW_MEMORY_POOL_ARG
EXPAND_AS_DEFINED = ARROW_MEMORY_POOL_DEFAULT

# If the SKIP_FUNCTION_MACROS tag is set to YES then doxygen's preprocessor will
# remove all references to function-like macros that are alone on a line, have
Expand Down
27 changes: 11 additions & 16 deletions cpp/src/arrow/builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,6 @@ struct Decimal;

static constexpr int64_t kMinBuilderCapacity = 1 << 5;

#ifdef ARROW_NO_DEFAULT_MEMORY_POOL
#define ARROW_MEMORY_POOL_ARG pool
#else
#define ARROW_MEMORY_POOL_ARG pool = default_memory_pool()
#endif

/// Base class for all data array builders.
//
/// This class provides a facilities for incrementally building the null bitmap
Expand Down Expand Up @@ -167,7 +161,8 @@ class ARROW_EXPORT ArrayBuilder {

class ARROW_EXPORT NullBuilder : public ArrayBuilder {
public:
explicit NullBuilder(MemoryPool* ARROW_MEMORY_POOL_ARG) : ArrayBuilder(null(), pool) {}
explicit NullBuilder(MemoryPool* pool ARROW_MEMORY_POOL_DEFAULT)
: ArrayBuilder(null(), pool) {}

Status AppendNull() {
++null_count_;
Expand Down Expand Up @@ -236,8 +231,8 @@ class ARROW_EXPORT NumericBuilder : public PrimitiveBuilder<T> {

template <typename T1 = T>
explicit NumericBuilder(
typename std::enable_if<TypeTraits<T1>::is_parameter_free, MemoryPool*>::type
ARROW_MEMORY_POOL_ARG)
typename std::enable_if<TypeTraits<T1>::is_parameter_free, MemoryPool*>::type pool
ARROW_MEMORY_POOL_DEFAULT)
: PrimitiveBuilder<T1>(TypeTraits<T1>::type_singleton(), pool) {}

using PrimitiveBuilder<T>::Append;
Expand Down Expand Up @@ -368,7 +363,7 @@ inline uint8_t ExpandedUIntSize(uint64_t val, uint8_t current_int_size) {

class ARROW_EXPORT AdaptiveUIntBuilder : public internal::AdaptiveIntBuilderBase {
public:
explicit AdaptiveUIntBuilder(MemoryPool* ARROW_MEMORY_POOL_ARG);
explicit AdaptiveUIntBuilder(MemoryPool* pool ARROW_MEMORY_POOL_DEFAULT);

using ArrayBuilder::Advance;

Expand Down Expand Up @@ -427,7 +422,7 @@ class ARROW_EXPORT AdaptiveUIntBuilder : public internal::AdaptiveIntBuilderBase

class ARROW_EXPORT AdaptiveIntBuilder : public internal::AdaptiveIntBuilderBase {
public:
explicit AdaptiveIntBuilder(MemoryPool* ARROW_MEMORY_POOL_ARG);
explicit AdaptiveIntBuilder(MemoryPool* pool ARROW_MEMORY_POOL_DEFAULT);

using ArrayBuilder::Advance;

Expand Down Expand Up @@ -486,7 +481,7 @@ class ARROW_EXPORT AdaptiveIntBuilder : public internal::AdaptiveIntBuilderBase

class ARROW_EXPORT BooleanBuilder : public ArrayBuilder {
public:
explicit BooleanBuilder(MemoryPool* ARROW_MEMORY_POOL_ARG);
explicit BooleanBuilder(MemoryPool* pool ARROW_MEMORY_POOL_DEFAULT);

explicit BooleanBuilder(const std::shared_ptr<DataType>& type, MemoryPool* pool);

Expand Down Expand Up @@ -607,7 +602,7 @@ class ARROW_EXPORT ListBuilder : public ArrayBuilder {
/// \brief Builder class for variable-length binary data
class ARROW_EXPORT BinaryBuilder : public ArrayBuilder {
public:
explicit BinaryBuilder(MemoryPool* ARROW_MEMORY_POOL_ARG);
explicit BinaryBuilder(MemoryPool* pool ARROW_MEMORY_POOL_DEFAULT);

#ifndef ARROW_NO_DEPRECATED_API
/// \deprecated Since 0.6.0
Expand Down Expand Up @@ -656,7 +651,7 @@ class ARROW_EXPORT BinaryBuilder : public ArrayBuilder {
class ARROW_EXPORT StringBuilder : public BinaryBuilder {
public:
using BinaryBuilder::BinaryBuilder;
explicit StringBuilder(MemoryPool* ARROW_MEMORY_POOL_ARG);
explicit StringBuilder(MemoryPool* pool ARROW_MEMORY_POOL_DEFAULT);

using BinaryBuilder::Append;

Expand All @@ -676,7 +671,7 @@ class ARROW_EXPORT FixedSizeBinaryBuilder : public ArrayBuilder {
#endif

FixedSizeBinaryBuilder(const std::shared_ptr<DataType>& type,
MemoryPool* ARROW_MEMORY_POOL_ARG);
MemoryPool* pool ARROW_MEMORY_POOL_DEFAULT);

Status Append(const uint8_t* value);
Status Append(const uint8_t* data, int64_t length,
Expand All @@ -699,7 +694,7 @@ class ARROW_EXPORT FixedSizeBinaryBuilder : public ArrayBuilder {
class ARROW_EXPORT DecimalBuilder : public FixedSizeBinaryBuilder {
public:
explicit DecimalBuilder(const std::shared_ptr<DataType>& type,
MemoryPool* ARROW_MEMORY_POOL_ARG);
MemoryPool* pool ARROW_MEMORY_POOL_DEFAULT);

#ifndef ARROW_NO_DEPRECATED_API
/// \deprecated Since 0.6.0
Expand Down
34 changes: 30 additions & 4 deletions cpp/src/arrow/gpu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,26 @@ set(ARROW_GPU_SHARED_LINK_LIBS
arrow_shared
)

cuda_add_library(arrow_gpu SHARED
add_library(arrow_gpu_objlib OBJECT
${ARROW_GPU_SRCS}
)
set_property(TARGET arrow_gpu_objlib PROPERTY POSITION_INDEPENDENT_CODE 1)

if (ARROW_BUILD_SHARED)
cuda_add_library(arrow_gpu_shared SHARED $<TARGET_OBJECTS:arrow_gpu_objlib>)
install(TARGETS arrow_gpu_shared
RUNTIME DESTINATION bin
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif()

if (ARROW_BUILD_STATIC)
add_library(arrow_gpu_static STATIC $<TARGET_OBJECTS:arrow_gpu_objlib>)
install(TARGETS arrow_gpu_static
RUNTIME DESTINATION bin
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif()

install(FILES
cuda_common.h
Expand All @@ -97,10 +114,19 @@ install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/arrow-gpu.pc"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig/")

set(ARROW_GPU_TEST_LINK_LIBS
arrow_gpu_shared
${ARROW_TEST_LINK_LIBS})

if (ARROW_BUILD_TESTS)
set(ARROW_GPU_TEST_LINK_LIBS
${ARROW_TEST_LINK_LIBS}
arrow_gpu)
ADD_ARROW_CUDA_TEST(cuda-test
STATIC_LINK_LIBS ${ARROW_GPU_TEST_LINK_LIBS})
endif()

if (ARROW_BUILD_BENCHMARKS)
cuda_add_executable(cuda-benchmark cuda-benchmark.cc)
target_link_libraries(cuda-benchmark
arrow_gpu_shared
gtest
${ARROW_BENCHMARK_LINK_LIBS})
endif()
93 changes: 93 additions & 0 deletions cpp/src/arrow/gpu/cuda-benchmark.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// 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.

#include "benchmark/benchmark.h"

#include <cstdint>
#include <memory>
#include <vector>

#include "arrow/array.h"
#include "arrow/memory_pool.h"
#include "arrow/test-util.h"

#include "arrow/gpu/cuda_memory.h"

namespace arrow {
namespace gpu {

constexpr int64_t kGpuNumber = 0;

static void CudaBufferWriterBenchmark(benchmark::State& state, const int64_t total_bytes,
const int64_t chunksize,
const int64_t buffer_size) {
std::shared_ptr<CudaBuffer> device_buffer;
ABORT_NOT_OK(AllocateCudaBuffer(kGpuNumber, total_bytes, &device_buffer));
CudaBufferWriter writer(device_buffer);

if (buffer_size > 0) {
ABORT_NOT_OK(writer.SetBufferSize(buffer_size));
}

std::shared_ptr<PoolBuffer> buffer;
ASSERT_OK(test::MakeRandomBytePoolBuffer(total_bytes, default_memory_pool(), &buffer));

const uint8_t* host_data = buffer->data();
while (state.KeepRunning()) {
int64_t bytes_written = 0;
ABORT_NOT_OK(writer.Seek(0));
while (bytes_written < total_bytes) {
int64_t bytes_to_write = std::min(chunksize, total_bytes - bytes_written);
ABORT_NOT_OK(writer.Write(host_data + bytes_written, bytes_to_write));
bytes_written += bytes_to_write;
}
}
state.SetBytesProcessed(int64_t(state.iterations()) * total_bytes);
}

static void BM_Writer_Buffered(benchmark::State& state) {
// 128MB
const int64_t kTotalBytes = 1 << 27;

// 8MB
const int64_t kBufferSize = 1 << 23;

CudaBufferWriterBenchmark(state, kTotalBytes, state.range(0), kBufferSize);
}

static void BM_Writer_Unbuffered(benchmark::State& state) {
// 128MB
const int64_t kTotalBytes = 1 << 27;
CudaBufferWriterBenchmark(state, kTotalBytes, state.range(0), 0);
}

// Vary chunk write size from 256 bytes to 64K
BENCHMARK(BM_Writer_Buffered)
->RangeMultiplier(16)
->Range(1 << 8, 1 << 16)
->MinTime(1.0)
->UseRealTime();

BENCHMARK(BM_Writer_Unbuffered)
->RangeMultiplier(4)
->RangeMultiplier(16)
->Range(1 << 8, 1 << 16)
->MinTime(1.0)
->UseRealTime();

} // namespace gpu
} // namespace arrow
Loading