TestRunGPU tests GPU injection using the --gpus flag.
(t *testing.T)
| 726 | |
| 727 | // TestRunGPU tests GPU injection using the --gpus flag. |
| 728 | func TestRunGPU(t *testing.T) { |
| 729 | t.Parallel() |
| 730 | // Although CDI injection is supported by Docker, specifying the --cdi-spec-dirs on the command line is not. |
| 731 | testutil.DockerIncompatible(t) |
| 732 | const nvidiaSpec = ` |
| 733 | cdiVersion: "0.5.0" |
| 734 | kind: "nvidia.com/gpu" |
| 735 | devices: |
| 736 | - name: "0" |
| 737 | containerEdits: |
| 738 | env: |
| 739 | - NVIDIA_GPU_0=injected |
| 740 | - name: "1" |
| 741 | containerEdits: |
| 742 | env: |
| 743 | - NVIDIA_GPU_1=injected |
| 744 | ` |
| 745 | const amdSpec = ` |
| 746 | cdiVersion: "0.5.0" |
| 747 | kind: "amd.com/gpu" |
| 748 | devices: |
| 749 | - name: "0" |
| 750 | containerEdits: |
| 751 | env: |
| 752 | - AMD_GPU_0=injected |
| 753 | - name: "1" |
| 754 | containerEdits: |
| 755 | env: |
| 756 | - AMD_GPU_1=injected |
| 757 | ` |
| 758 | const unknownSpec = ` |
| 759 | cdiVersion: "0.5.0" |
| 760 | kind: "unknown.com/gpu" |
| 761 | devices: |
| 762 | - name: "0" |
| 763 | containerEdits: |
| 764 | env: |
| 765 | - UNKNOWN_GPU_0=injected |
| 766 | ` |
| 767 | |
| 768 | testCases := []struct { |
| 769 | name string |
| 770 | specs map[string]string |
| 771 | gpuFlags []string |
| 772 | expectedEnvs []string |
| 773 | expectFail bool |
| 774 | }{ |
| 775 | { |
| 776 | name: "nvidia device injection", |
| 777 | specs: map[string]string{"nvidia.yaml": nvidiaSpec}, |
| 778 | gpuFlags: []string{"--gpus", "2"}, |
| 779 | expectedEnvs: []string{"NVIDIA_GPU_0=injected", "NVIDIA_GPU_1=injected"}, |
| 780 | }, |
| 781 | { |
| 782 | name: "amd device injection", |
| 783 | specs: map[string]string{"amd.yaml": amdSpec}, |
| 784 | gpuFlags: []string{"--gpus", "2"}, |
| 785 | expectedEnvs: []string{"AMD_GPU_0=injected", "AMD_GPU_1=injected"}, |
nothing calls this directly
no test coverage detected
searching dependent graphs…