src/runtime/directx/directx_workspace.cc
// Alignment and type_hint not works in DirectX, better use runtime default
Alignment and type_hint not works in DirectX, better use runtime default
Alignment and type_hint not works in DirectX better use runtime default
void* DirectXWorkspace::AllocDataSpace(Device dev, size_t nbytes, size_t alignment,
                                       DLDataType type_hint) {
  uint64_t handle = 0;
  if (static_cast<int>(dev.device_type) == kDLDirectXHost ||
      static_cast<int>(dev.device_type) == kDLDirectXUpload) {
    auto buff = this->dx_device->host_buffer(nbytes, type_hint, DirectHostBuffer::hostbuffer_state::upload);
    handle = (uint64_t)buff.get();
    device_state[dev_to_uint32(dev)].buffer[handle] = buff;
  } else if (static_cast<int>(dev.device_type) == kDLDirectXReadback) {
    auto buff = this->dx_device->host_buffer(nbytes, type_hint, DirectHostBuffer::hostbuffer_state::readback);
    handle = (uint64_t)buff.get();
    device_state[dev_to_uint32(dev)].buffer[handle] = buff;
  } else if (static_cast<int>(dev.device_type) == kDLDirectX) {
    auto buff = this->dx_context->get_device(dev.device_id)->device_buffer(nbytes, type_hint);
    handle = (uint64_t)buff.get();
    device_state[dev_to_uint32(dev)].buffer[handle] = buff;
  } else if (dev.device_type = kDLCPU) {
    handle = (uint64_t)malloc(nbytes);
  } else
    throw std::invalid_argument(_msg_("Target buffer state is not supported."));
  return (void*)(handle);
}
void * DirectXWorkspace :: AllocDataSpace ( Device dev , size_t nbytes , size_t alignment , DLDataType type_hint ) { uint64_t handle = 0 ; if ( static_cast < int > ( dev . device_type ) == kDLDirectXHost || static_cast < int > ( dev . device_type ) == kDLDirectXUpload ) { auto buff = this -> dx_device -> host_buffer ( nbytes , type_hint , DirectHostBuffer :: hostbuffer_state :: upload ) ; handle = ( uint64_t ) buff . get ( ) ; device_state [ dev_to_uint32 ( dev ) ] . buffer [ handle ] = buff ; } else if ( static_cast < int > ( dev . device_type ) == kDLDirectXReadback ) { auto buff = this -> dx_device -> host_buffer ( nbytes , type_hint , DirectHostBuffer :: hostbuffer_state :: readback ) ; handle = ( uint64_t ) buff . get ( ) ; device_state [ dev_to_uint32 ( dev ) ] . buffer [ handle ] = buff ; } else if ( static_cast < int > ( dev . device_type ) == kDLDirectX ) { auto buff = this -> dx_context -> get_device ( dev . device_id ) -> device_buffer ( nbytes , type_hint ) ; handle = ( uint64_t ) buff . get ( ) ; device_state [ dev_to_uint32 ( dev ) ] . buffer [ handle ] = buff ; } else if ( dev . device_type = kDLCPU ) { handle = ( uint64_t ) malloc ( nbytes ) ; } else throw std :: invalid_argument ( _msg_ ( " " ) ) ; return ( void * ) ( handle ) ; }
Alignment and type_hint not works in DirectX, better use runtime default
Alignment and type_hint not works in DirectX better use runtime default
// Allocate host(RAM) memory buffer // Allocate VRAM buffer // this is a trick: return the offet as void*