Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for GPU sharing on GKE #6628

Merged
merged 4 commits into from
Oct 6, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2274,6 +2274,10 @@ resource "google_container_node_pool" "np_with_gpu" {
type = "nvidia-tesla-a100"
gpu_partition_size = "1g.5gb"
count = 1
gpu_sharing_config {
gpu_sharing_strategy = "TIME_SHARING"
max_shared_clients_per_gpu = 2
}
grac3gao marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Expand Down
53 changes: 49 additions & 4 deletions mmv1/third_party/terraform/utils/node_config.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,30 @@ func schemaNodeConfig() *schema.Schema {
ForceNew: true,
Description: `Size of partitions to create on the GPU. Valid values are described in the NVIDIA mig user guide (https://docs.nvidia.com/datacenter/tesla/mig-user-guide/#partitioning)`,
},
"gpu_sharing_config": &schema.Schema{
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
ForceNew: true,
ConfigMode: schema.SchemaConfigModeAttr,
Description: `The configuration for GPU sharing options.`,
grac3gao marked this conversation as resolved.
Show resolved Hide resolved
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"gpu_sharing_strategy": &schema.Schema{
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: `The type of GPU sharing strategy to enable on the GPU node. Possible value is TIME_SHARING`,
grac3gao marked this conversation as resolved.
Show resolved Hide resolved
},
"max_shared_clients_per_gpu": &schema.Schema{
Type: schema.TypeInt,
Required: true,
ForceNew: true,
Description: `The max number of containers that can share a GPU.`,
grac3gao marked this conversation as resolved.
Show resolved Hide resolved
},
},
},
},
},
},
},
Expand Down Expand Up @@ -491,11 +515,23 @@ func expandNodeConfig(v interface{}) *container.NodeConfig {
if data["count"].(int) == 0 {
continue
}
guestAccelerators = append(guestAccelerators, &container.AcceleratorConfig{
guestAcceleratorConfig := &container.AcceleratorConfig{
AcceleratorCount: int64(data["count"].(int)),
AcceleratorType: data["type"].(string),
GpuPartitionSize: data["gpu_partition_size"].(string),
})
}

if v, ok := data["gpu_sharing_config"]; ok {
if len(v.([]interface{})) > 0 {
grac3gao marked this conversation as resolved.
Show resolved Hide resolved
gpuSharingConfig := data["gpu_sharing_config"].([]interface{})[0].(map[string]interface{})
guestAcceleratorConfig.GpuSharingConfig = &container.GPUSharingConfig{
GpuSharingStrategy: gpuSharingConfig["gpu_sharing_strategy"].(string),
MaxSharedClientsPerGpu: int64(gpuSharingConfig["max_shared_clients_per_gpu"].(int)),
}
}
}

guestAccelerators = append(guestAccelerators, guestAcceleratorConfig)
}
nc.Accelerators = guestAccelerators
}
Expand Down Expand Up @@ -795,11 +831,20 @@ func flattenNodeConfig(c *container.NodeConfig) []map[string]interface{} {
func flattenContainerGuestAccelerators(c []*container.AcceleratorConfig) []map[string]interface{} {
result := []map[string]interface{}{}
for _, accel := range c {
result = append(result, map[string]interface{}{
accelerator := map[string]interface{}{
"count": accel.AcceleratorCount,
"type": accel.AcceleratorType,
"gpu_partition_size": accel.GpuPartitionSize,
})
}
if accel.GpuSharingConfig != nil {
accelerator["gpu_sharing_config"] = []map[string]interface{}{
{
"gpu_sharing_strategy": accel.GpuSharingConfig.GpuSharingStrategy,
"max_shared_clients_per_gpu": accel.GpuSharingConfig.MaxSharedClientsPerGpu,
},
}
}
result = append(result, accelerator)
}
return result
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,16 @@ linux_node_config {

* `gpu_partition_size` (Optional) - Size of partitions to create on the GPU. Valid values are described in the NVIDIA mig [user guide](https://docs.nvidia.com/datacenter/tesla/mig-user-guide/#partitioning).

* `gpu_sharing_config` (Optional) - The configuration for GPU sharing options. Structure is [documented below](#nested_gpu_sharing_config).

<a name="nested_gpu_sharing_config"></a>The `gpu_sharing_config` block supports:

* `gpu_sharing_strategy` (Required) - The type of GPU sharing strategy to enable on the GPU node.
Accepted values are:
* `"TIME_SHARING"`: Allow multiple containers to have [time-shared](https://cloud.google.com/kubernetes-engine/docs/concepts/timesharing-gpus) access to a single GPU device.

* `max_shared_clients_per_gpu` (Required) - The max number of containers that can share a GPU.

<a name="nested_workload_identity_config"></a> The `workload_identity_config` block supports:

* `workload_pool` (Optional) - The workload pool to attach all Kubernetes service accounts to.
Expand Down