MCPcopy Create free account
hub / github.com/apache/arrow / ExportBuffer

Function ExportBuffer

cpp/src/arrow/c/dlpack.cc:98–134  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

96
97template <typename DT, typename Vec>
98DT* ExportBuffer(ExportBufferParams<Vec>&& p) {
99 // Create ManagerCtx that will serve as the owner of the DLManagedTensor
100 using Ctx = ManagerCtx<DT, Vec>;
101 auto ctx = std::make_unique<Ctx>();
102
103 // Assign the Array data, shape, and strides into the context.
104 ctx->buffer = std::move(p.buffer);
105 ctx->shape = std::move(p.shape);
106 ctx->strides = std::move(p.strides);
107
108 // Define the data pointer to the DLTensor
109 // If array is of length 0, data pointer should be NULL
110 if (p.size == 0) {
111 ctx->tensor.dl_tensor.data = nullptr;
112 } else {
113 ctx->tensor.dl_tensor.data =
114 const_cast<uint8_t*>(ctx->buffer->data() + p.buffer_offset);
115 }
116
117 ctx->tensor.dl_tensor.device = p.device;
118 ctx->tensor.dl_tensor.dtype = p.dtype;
119 ctx->tensor.dl_tensor.ndim = p.ndim;
120 ctx->tensor.dl_tensor.shape = ctx->shape.data();
121 ctx->tensor.dl_tensor.byte_offset = 0;
122 // Strides must be non-null when ndim > 0
123 ctx->tensor.dl_tensor.strides = ctx->strides.data();
124 if constexpr (std::is_same_v<DT, DLManagedTensorVersioned>) {
125 ctx->tensor.version = kVersion;
126 ctx->tensor.flags = p.flags;
127 }
128
129 ctx->tensor.manager_ctx = ctx.get();
130 ctx->tensor.deleter = [](DT* self) {
131 delete reinterpret_cast<Ctx*>(self->manager_ctx);
132 };
133 return &ctx.release()->tensor;
134}
135
136template <typename DT>
137Result<DT*> ExportArrayImpl(const std::shared_ptr<Array>& arr, bool copy) {

Callers

nothing calls this directly

Calls 3

dataMethod · 0.45
getMethod · 0.45
releaseMethod · 0.45

Tested by

no test coverage detected