Uploaded image for project: 'Apache Arrow'
  1. Apache Arrow
  2. ARROW-2447

[C++] Create a device abstraction

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 0.9.0
    • 0.17.0
    • C++, GPU

    Description

      Right now, a plain Buffer doesn't carry information about where it actually lies. That information also cannot be passed around, so you get APIs like PlasmaClient which take or return device number integers, and have implementations which hardcode operations on CUDA buffers. Also, unsuspecting receivers of a Buffer pointer may try to act on the underlying memory without knowing whether it's CPU-reachable or not.

      Here is a sketch for a proposed Device abstraction:

      class Device {
          enum DeviceKind { KIND_CPU, KIND_CUDA };
      
          virtual DeviceKind kind() const;
          //MemoryPool* default_memory_pool() const;
          //std::shared_ptr<Buffer> Allocate(...);
      };
      
      class CpuDevice : public Device {};
      
      class CudaDevice : public Device {
          int device_num() const;
      };
      
      class Buffer {
          virtual DeviceKind device_kind() const;
          virtual std::shared_ptr<Device> device() const;
          virtual bool on_cpu() const {
              return true;
          }
      
          const uint8_t* cpu_data() const {
              return on_cpu() ? data() : nullptr;
          }
          uint8_t* cpu_mutable_data() {
              return on_cpu() ? mutable_data() : nullptr;
          }
      
          virtual CopyToCpu(std::shared_ptr<Buffer> dest) const;
          virtual CopyFromCpu(std::shared_ptr<Buffer> src);
      };
      
      class CudaBuffer : public Buffer {
          virtual bool on_cpu() const {
              return false;
          }
      };
      
      CopyBuffer(std::shared_ptr<Buffer> dest, const std::shared_ptr<Buffer> src);
      

      Attachments

        Issue Links

          Activity

            People

              apitrou Antoine Pitrou
              apitrou Antoine Pitrou
              Votes:
              0 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 9h 50m
                  9h 50m