gpu_test.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. Copyright 2020 Docker, Inc.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package ecs
  14. import (
  15. "testing"
  16. )
  17. func TestGuessMachineType(t *testing.T) {
  18. tests := []struct {
  19. name string
  20. yaml string
  21. want string
  22. wantErr bool
  23. }{
  24. {
  25. name: "1-gpus",
  26. yaml: `
  27. services:
  28. learning:
  29. image: tensorflow/tensorflow:latest-gpus
  30. deploy:
  31. resources:
  32. reservations:
  33. generic_resources:
  34. - discrete_resource_spec:
  35. kind: gpus
  36. value: 1
  37. `,
  38. want: "p3.2xlarge",
  39. wantErr: false,
  40. },
  41. {
  42. name: "4-gpus",
  43. yaml: `
  44. services:
  45. learning:
  46. image: tensorflow/tensorflow:latest-gpus
  47. deploy:
  48. resources:
  49. reservations:
  50. generic_resources:
  51. - discrete_resource_spec:
  52. kind: gpus
  53. value: 4
  54. `,
  55. want: "p3.8xlarge",
  56. wantErr: false,
  57. },
  58. {
  59. name: "1-gpus, high-memory",
  60. yaml: `
  61. services:
  62. learning:
  63. image: tensorflow/tensorflow:latest-gpus
  64. deploy:
  65. resources:
  66. reservations:
  67. memory: 300Gb
  68. generic_resources:
  69. - discrete_resource_spec:
  70. kind: gpus
  71. value: 2
  72. `,
  73. want: "p3.16xlarge",
  74. wantErr: false,
  75. },
  76. {
  77. name: "1-gpus, high-cpu",
  78. yaml: `
  79. services:
  80. learning:
  81. image: tensorflow/tensorflow:latest-gpus
  82. deploy:
  83. resources:
  84. reservations:
  85. memory: 32Gb
  86. cpus: "32"
  87. generic_resources:
  88. - discrete_resource_spec:
  89. kind: gpus
  90. value: 2
  91. `,
  92. want: "p3.8xlarge",
  93. wantErr: false,
  94. },
  95. }
  96. for _, tt := range tests {
  97. t.Run(tt.name, func(t *testing.T) {
  98. project := loadConfig(t, tt.yaml)
  99. got, err := guessMachineType(project)
  100. if (err != nil) != tt.wantErr {
  101. t.Errorf("guessMachineType() error = %v, wantErr %v", err, tt.wantErr)
  102. return
  103. }
  104. if got != tt.want {
  105. t.Errorf("guessMachineType() got = %v, want %v", got, tt.want)
  106. }
  107. })
  108. }
  109. }