Class: SGC::CU::CUDevicePtr

Inherits:
Object
  • Object
show all
Defined in:
lib/cuda/driver/deviceptr.rb

Instance Method Summary collapse

Instance Method Details

#attribute(attrib) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/cuda/driver/deviceptr.rb', line 56

def attribute(attrib)
    case attrib
    when :CONTEXT
        p = FFI::MemoryPointer.new(:CUContext)
        status = API::cuPointerGetAttribute(p, attrib, self.to_api)
        Pvt::handle_error(status, "Failed to get pointer context.")
        r = CUContext.send(:new, p)
    when :MEMORY_TYPE
        p = FFI::MemoryPointer.new(:uint)
        status = API::cuPointerGetAttribute(p, attrib, self.to_api)
        Pvt::handle_error(status, "Failed to get pointer memory type.")
        r = CUMemoryType[p.read_uint]
    when :DEVICE_POINTER
        p = FFI::MemoryPointer.new(:CUDevicePtr)
        status = API::cuPointerGetAttribute(p, attrib, self.to_api)
        Pvt::handle_error(status, "Failed to get device pointer.")
        r = CUDevicePtr.send(:new, p)
    when :HOST_POINTER
        p = FFI::MemoryPointer.new(:pointer)
        status = API::cuPointerGetAttribute(p, attrib, self.to_api)
        Pvt::handle_error(status, "Failed to get host pointer.")
        r = SGC::Memory::MemoryPointer.new(p.read_pointer)
    else
        raise TypeError, "Expect _attrib_ one of #{CUPointerAttribute.symbols}, but we get #{attrib}."
    end
    r
end

#freeObject

Free the allocated device memory that this pointer pointing to.



37
38
39
40
41
42
# File 'lib/cuda/driver/deviceptr.rb', line 37

def free
    status = API::cuMemFree(API::read_cudeviceptr(@pdevptr))
    Pvt::handle_error(status, "Failed to free device memory.")
    API::write_cudeviceptr(@pdevptr, 0)
    nil
end

#offset(index) ⇒ CUDevicePtr



48
49
50
51
52
53
# File 'lib/cuda/driver/deviceptr.rb', line 48

def offset(index)
    p = FFI::MemoryPointer.new(:CUDevicePtr)
    addr = API::read_cudeviceptr(@pdevptr).to_i + index
    API::write_cudeviceptr(p, addr)
    CUDevicePtr.send(:new, p)
end