mirror of
https://github.com/moby/moby.git
synced 2026-01-11 02:31:44 +00:00
Added backend code to support the exact same interface used today for Nvidia GPUs, allowing customers to use the same docker commands for both Nvidia and AMD GPUs. Signed-off-by: Sudheendra Gopinath <sudheendra.gopinath@amd.com> Reused common functions from nvidia_linux.go. Removed duplicate code in amd_linux.go by reusing the init() and countToDevices() functions in nvidia_linux.go. AMD driver is registered in init(). Signed-off-by: Sudheendra Gopinath <sudheendra.gopinath@amd.com> Renamed amd-container-runtime constant Signed-off-by: Sudheendra Gopinath <sudheendra.gopinath@amd.com> Removed empty branch to keep linter happy. Also renamed amd_linux.go to gpu_amd_linux.go. Signed-off-by: Sudheendra Gopinath <sudheendra.gopinath@amd.com> Renamed nvidia_linux.go and gpu_amd_linux.go. Signed-off-by: Sudheendra Gopinath <sudheendra.gopinath@amd.com>
28 lines
697 B
Go
28 lines
697 B
Go
package daemon
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/opencontainers/runtime-spec/specs-go"
|
|
)
|
|
|
|
func setAMDGPUs(s *specs.Spec, dev *deviceInstance) error {
|
|
req := dev.req
|
|
if req.Count != 0 && len(req.DeviceIDs) > 0 {
|
|
return errConflictCountDeviceIDs
|
|
}
|
|
|
|
switch {
|
|
case len(req.DeviceIDs) > 0:
|
|
s.Process.Env = append(s.Process.Env, "AMD_VISIBLE_DEVICES="+strings.Join(req.DeviceIDs, ","))
|
|
case req.Count > 0:
|
|
s.Process.Env = append(s.Process.Env, "AMD_VISIBLE_DEVICES="+countToDevices(req.Count))
|
|
case req.Count < 0:
|
|
s.Process.Env = append(s.Process.Env, "AMD_VISIBLE_DEVICES=all")
|
|
case req.Count == 0:
|
|
s.Process.Env = append(s.Process.Env, "AMD_VISIBLE_DEVICES=void")
|
|
}
|
|
|
|
return nil
|
|
}
|