Skip to content

GH-41670: [C++][Python] Move to DLPack 1.3 - #50827

Open
AntoinePrv wants to merge 3 commits into
apache:mainfrom
AntoinePrv:dl-version
Open

GH-41670: [C++][Python] Move to DLPack 1.3#50827
AntoinePrv wants to merge 3 commits into
apache:mainfrom
AntoinePrv:dl-version

Conversation

@AntoinePrv

@AntoinePrv AntoinePrv commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

Rationale for this change

Pure version bump to enable implementing more features.

What changes are included in this PR?

  • Change the DLPack header file and definition.
  • Use raw_data for Tensor similar to Array (instead of mutable_raw_data that is not available on immutable tensors).
  • Strides may no longer be NULL
  • Add ExportArrayVersioned and ExportTensorVersioned C APIs

Are these changes tested?

Yes, with existing tests.

Are there any user-facing changes?

@AntoinePrv
AntoinePrv requested a review from pitrou as a code owner August 6, 2026 13:30
Copilot AI lite review requested due to automatic review settings August 6, 2026 13:30
@AntoinePrv AntoinePrv changed the title GH-41670: [C++][Python] Move to DLPack 1.3.0 GH-41670: [C++][Python] Move to DLPack 1.3 Aug 6, 2026
@github-actions github-actions Bot added the awaiting review Awaiting review label Aug 6, 2026
@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown

⚠️ GitHub issue #41670 has been automatically assigned in GitHub to PR creator.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Arrow’s current DLPack Array exporter still emits strides = NULL (non-compliant with DLPack v1.2+ requirements) and the new header text contains documentation mismatches that should be corrected.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.

Pull request overview

Updates Arrow’s vendored DLPack ABI header to DLPack v1.3, expanding the ABI surface (new device/type enums, flags, and the __dlpack_c_exchange_api__ protocol) while bumping the reported minor version.

Changes:

  • Bump DLPack minor version to 1.3 and sync header contents to a newer upstream commit.
  • Add new DLDeviceType/DLDataTypeCode values and additional DLManagedTensorVersioned flag bitmasks.
  • Introduce DLPack fast exchange protocol (DLPackExchangeAPI*) type definitions and documentation.
File summaries
File Description
cpp/src/arrow/c/dlpack_abi.h Vendor update to DLPack 1.3 ABI definitions, enums, flags, and fast exchange protocol types.
Review details

Suppressed comments (1)

cpp/src/arrow/c/dlpack_abi.h:426

  • The documentation for DLPackManagedTensorFromPyObjectNoSync claims the function returns an owning pointer/NULL, but the typedef returns int and delivers the tensor via out. The return contract should match the signature.
 * \return The owning DLManagedTensorVersioned* or NULL on failure with a
 *         Python exception set. If the data cannot be described using DLPack
 *         this should be a BufferError if possible.
 * \note - As a C function, must not thrown C++ exceptions.
  • Files reviewed: 1/1 changed files
  • Comments generated: 3
  • Review effort level: Lite

We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.

Comment thread cpp/src/arrow/c/dlpack_abi.h
Comment thread cpp/src/arrow/c/dlpack_abi.h
Comment thread cpp/src/arrow/c/dlpack_abi.h
@github-actions github-actions Bot added awaiting committer review Awaiting committer review and removed awaiting review Awaiting review labels Aug 6, 2026
Copilot AI review requested due to automatic review settings August 6, 2026 15:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The new public versioned export APIs are not covered by tests, and there is a small but concrete maintainability issue (std::move on a const shared_ptr reference) to address.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.

Review details

Suppressed comments (3)

cpp/src/arrow/c/dlpack.cc:212

  • t is a const std::shared_ptr<Tensor>&, so std::move(t) won’t actually move (it will fall back to a copy via operator=(const shared_ptr&)). Using a plain copy here is clearer and avoids the misleading std::move.
  ctx->t = std::move(t);

cpp/src/arrow/c/dlpack_test.cc:49

  • New public APIs ExportArrayVersioned/ExportTensorVersioned (and the version/flags fields they populate) aren’t covered by tests here; currently the tests only exercise the legacy ExportArray/ExportTensor paths. Adding a small set of assertions for version/flags on the versioned exports would prevent regressions.
  ASSERT_EQ(1, *dltensor.strides);  // Must be non-null with ndim>0 since 1.2

cpp/src/arrow/c/dlpack.h:48

  • ExportTensor also returns the legacy DLManagedTensor (deprecated in DLPack in favor of DLManagedTensorVersioned), but only ExportArray is annotated as deprecated in this header. To keep the API docs consistent and steer callers to the versioned path, add the same deprecation note for ExportTensor.
ARROW_EXPORT
Result<DLManagedTensor*> ExportTensor(const std::shared_ptr<Tensor>& t);
  • Files reviewed: 4/4 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.

Copilot AI review requested due to automatic review settings August 6, 2026 15:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

cpp/src/arrow/c/dlpack.cc has missing semicolons after ARROW_ASSIGN_OR_RAISE statements that will break compilation.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.

Review details

Suppressed comments (1)

cpp/src/arrow/c/dlpack.cc:175

  • Missing semicolon after ARROW_ASSIGN_OR_RAISE; as written this won’t compile because the macro expansion isn’t terminated as a statement.
  ARROW_ASSIGN_OR_RAISE(auto device, ExportDevice(t))
  • Files reviewed: 4/4 changed files
  • Comments generated: 1
  • Review effort level: Lite

We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.

Comment thread cpp/src/arrow/c/dlpack.cc
Copilot AI review requested due to automatic review settings August 6, 2026 15:35
@AntoinePrv

Copy link
Copy Markdown
Collaborator Author

@AlenkaF would you mind providing early feedback before I move on to the Python side.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The legacy ExportTensor path now exposes immutable tensor memory without a read-only signal, which can violate Arrow’s immutability contract unless behavior/tests are adjusted accordingly.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.

Review details

Suppressed comments (2)

cpp/src/arrow/c/dlpack.h:48

  • ExportTensor is also a legacy (pre-versioned) DLPack API, but only ExportArray is documented as deprecated. This makes the header inconsistent and can mislead users into using the legacy tensor export instead of the versioned API.
ARROW_EXPORT
Result<DLManagedTensor*> ExportTensor(const std::shared_ptr<Tensor>& t);

cpp/src/arrow/c/dlpack_test.cc:265

  • This test currently validates exporting an immutable tensor for both legacy and versioned producers. If the legacy API is made to reject immutable tensors (since it cannot express read-only), the test should branch: expect a TypeError for LegacyProducer and continue to validate successful export + read-only flag for VersionedProducer.
  CheckDLTensor<TypeParam>(read_only_tensor, float32(), DLDataTypeCode::kDLFloat, shape,
                           dlpack_strides);
}
  • Files reviewed: 4/4 changed files
  • Comments generated: 1
  • Review effort level: Lite

We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.

Comment thread cpp/src/arrow/c/dlpack.cc
Comment on lines 182 to 186
if (t->size() == 0) {
ctx->tensor.dl_tensor.data = NULL;
ctx->tensor.dl_tensor.data = nullptr;
} else {
ctx->tensor.dl_tensor.data = t->raw_mutable_data();
ctx->tensor.dl_tensor.data = const_cast<uint8_t*>(t->raw_data());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants