Skip to content

Devices ​

In AMDGPU, all GPU devices are auto-detected by the runtime, if they're supported.

Each Julia task has a current device, used for kernel launches and array allocations unless another device is specified via @roc or an equivalent interface. The device bound to the current task is accessible via AMDGPU.device method. The list of available devices can be queried with AMDGPU.devices method.

If you have a HIPDevice object, you can also switch the device with AMDGPU.device!. This switches the calling task, and also makes the device the default device, which tasks start on the first time they use AMDGPU. Pass a function to switch only while it runs, without changing the default.

julia
xd1 = AMDGPU.ones(Float32, 16) # On `AMDGPU.device()` device.

AMDGPU.device!(AMDGPU.devices()[2]) # Switch to second device.
xd2 = AMDGPU.ones(Float32, 16) # On second device.

AMDGPU.device!(AMDGPU.devices()[1]) do
    xd3 = AMDGPU.ones(Float32, 16) # On first device.
end # Back on second device.

To change only the device that new tasks start on, use AMDGPU.default_device!:

julia
AMDGPU.default_device!(AMDGPU.devices()[3]) # New tasks start on third device.
Threads.@spawn begin
    x = AMDGPU.ones(Float32, 16) # On third device.
    return
end

Additionally, devices have an associated numeric ID. This value is bounded between 1 and length(AMDGPU.devices()), and device 1 is the default device when AMDGPU is first loaded. The ID of the device associated with the current task can be queried with AMDGPU.device_id and changed with AMDGPU.device_id!.

AMDGPU.HIP.devices Function
julia
devices()

Get list of all devices.

source
AMDGPU.device Function
julia
device()::HIPDevice

Get currently active device. This device is used when launching kernels via @roc.

source
julia
device(A::ROCArray) -> HIPDevice

Return the device associated with the array A.

source
AMDGPU.device! Function
julia
device!(device::HIPDevice)
device!(f::Function, device::HIPDevice)

Switch the calling task to device, and make it the default_device, so that tasks which have not used AMDGPU yet start on it too. Use default_device! to change only the default.

With f, switch the calling task to device only while f runs. This leaves the default device unchanged.

source
AMDGPU.default_device Function
julia
default_device()::HIPDevice

Device that a task starts on, the first time it uses AMDGPU. This is the first device, until changed with default_device! or device!.

source
AMDGPU.default_device! Function
julia
default_device!(device::HIPDevice)

Make device the one that tasks start on, the first time they use AMDGPU. Unlike device!, this does not switch the calling task, nor any other task that already uses AMDGPU.

source
AMDGPU.device_id Function
julia
device_id() -> Int
device_id(device::HIPDevice) -> Int

Returns the numerical device ID for device or for the current AMDGPU.device().

source
AMDGPU.device_id! Function
julia
device_id!(idx::Integer)

Same as device!(AMDGPU.devices()[idx]), so it also sets the default device. See device_id for details on the numbering semantics.

source

Device Properties ​

AMDGPU.HIP.name Function
julia
name(dev::HIPDevice)::String

Get name of the device.

source
AMDGPU.HIP.wavefrontsize Function
julia
wavefrontsize(d::HIPDevice)::Cint

Get size of the wavefront. AMD GPUs support either 32 or 64.

source
AMDGPU.HIP.gcn_arch Function
julia
gcn_arch(d::HIPDevice)::String

Get GCN architecture for the device.

source
AMDGPU.HIP.device_id Function
julia
device_id(d::HIPDevice)

Zero-based device ID as expected by HIP functions. Differs from AMDGPU.device_id method by 1.

source
AMDGPU.HIP.properties Function
julia
properties(dev::HIPDevice)::hipDeviceProp_t

Get all properties for the device. See HIP documentation for hipDeviceProp_t for the meaning of each field.

source