zeroshade commented on code in PR #36489:
URL: https://github.com/apache/arrow/pull/36489#discussion_r1270794352
##########
cpp/src/arrow/c/bridge_test.cc:
##########
@@ -1112,6 +1130,391 @@ TEST_F(TestArrayExport, ExportRecordBatch) {
}
}
+////////////////////////////////////////////////////////////////////////////
+// Device Array Export Tests
+
+static const char kMyDeviceTypeName[] = "arrowtest::MyDevice";
+static const ArrowDeviceType kMyDeviceType = ARROW_DEVICE_EXT_DEV;
+
+class MyBuffer final : public MutableBuffer {
+ public:
+ using MutableBuffer::MutableBuffer;
+
+ ~MyBuffer() { default_memory_pool()->Free(const_cast<uint8_t*>(data_),
size_); }
+};
+
+class MyMemoryManager : public CPUMemoryManager {
+ public:
+ explicit MyMemoryManager(const std::shared_ptr<Device>& device)
+ : CPUMemoryManager(device, default_memory_pool()) {}
+
+ Result<std::unique_ptr<Buffer>> AllocateBuffer(int64_t size) override {
+ uint8_t* data;
+ RETURN_NOT_OK(pool_->Allocate(size, &data));
+ return std::make_unique<MyBuffer>(data, size, shared_from_this());
+ }
+
+ protected:
+ Result<std::shared_ptr<Buffer>> CopyBufferFrom(
+ const std::shared_ptr<Buffer>& buf,
+ const std::shared_ptr<MemoryManager>& from) override {
+ return CopyNonOwnedFrom(*buf, from);
+ }
+ Result<std::unique_ptr<Buffer>> CopyNonOwnedFrom(
+ const Buffer& buf, const std::shared_ptr<MemoryManager>& from) override {
+ if (!from->is_cpu()) {
+ return nullptr;
+ }
+
+ ARROW_ASSIGN_OR_RAISE(auto dest, AllocateBuffer(buf.size()));
+ if (buf.size() > 0) {
+ memcpy(dest->mutable_data(), buf.data(),
static_cast<size_t>(buf.size()));
+ }
+ return std::move(dest);
+ }
+};
+
+class MyDevice : public Device {
+ public:
+ explicit MyDevice(int value) : Device(true), value_(value) {}
+ const char* type_name() const override { return kMyDeviceTypeName; }
+ std::string ToString() const override { return kMyDeviceTypeName; }
+ bool Equals(const Device& other) const override {
+ if (other.type_name() != kMyDeviceTypeName) {
Review Comment:
Mostly because I was just copying the way that `CudaDevice` implemented the
function. But in theory you're right, it should compare both. I'll update that.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]