Configure GPU sharing without GPU memory isolation
In some cases, you might not need GPU Memory Isolation when using GPU Sharing. For example, if your application manages its own GPU Memory limits—similar to how a Java application can specify its maximum heap size at startup—enabling platform-level memory isolation can cause unexpected issues. This topic describes how to configure GPU Sharing on specific nodes without GPU Memory Isolation.
Prerequisites
-
You have created an ACK Dedicated Cluster with GPU-accelerated nodes. For more information, see Create an ACK Dedicated Cluster with GPU-accelerated nodes.
-
You have installed the ack-cgpu component. For more information, see Install the ack-cgpu component.
Step 1: Create a node pool
Create a Node Pool without the GPU Memory Isolation module.
Log on to the ACK console. In the left navigation pane, click Clusters.
-
On the Clusters page, click the name of your cluster and choose in the left-side navigation pane.
-
On the Node Pools page, click Create Node Pool. In the Create Node Pool dialog box, configure the parameters and click Confirm.
The following are the key parameters. For more information about other parameters, see Create and manage a Node Pool.
-
Expected Nodes: The initial number of nodes in the Node Pool. You can set this to 0 if you do not want to add nodes immediately.
-
Node Label: Add a label to the nodes to enable GPU Sharing. For more information about labels, see Scheduling labels.
Click the
icon, set Key to gpushareand Value totrue.
-
Step 2: Submit a Job
Log on to the ACK console. In the left navigation pane, click Clusters.
On the Clusters page, click the name of your cluster. In the left navigation pane, click .
-
On the Jobs page, click Create from YAML. On the Create page, paste the following YAML into the code editor and click Create.
apiVersion: batch/v1 kind: Job metadata: name: tensorflow-mnist-share spec: parallelism: 1 template: metadata: labels: app: tensorflow-mnist-share spec: containers: - name: tensorflow-mnist-share image: registry.cn-beijing.aliyuncs.com/ai-samples/gpushare-sample:tensorflow-1.5 command: - python - tensorflow-sample-code/tfjob/docker/mnist/main.py - --max_steps=100000 - --data_dir=tensorflow-sample-code/data resources: limits: aliyun.com/gpu-mem: 4 # Request 4 GiB of GPU memory. workingDir: /root restartPolicy: NeverThis YAML manifest defines a Job that:
-
Runs a TensorFlow MNIST sample application.
-
Creates one Pod that requests 4 GiB of GPU Memory by setting the
aliyun.com/gpu-mem: 4field underresources.limits.
-
Step 3: Verify sharing without isolation
Log on to the ACK console. In the left navigation pane, click Clusters.
On the Clusters page, click the name of your cluster. In the left navigation pane, click .
-
On the Pods page, find the Pod created in Step 2. In the Actions column, choose to open a shell session in the container.
-
Run the following command to check the GPU Memory status:
nvidia-smiExpected output:
Wed Jun 14 06:45:56 2023 +-----------------------------------------------------------------------------+ | NVIDIA-SMI 515.105.01 Driver Version: 515.105.01 CUDA Version: 11.7 | |-------------------------------+----------------------+----------------------+ | GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC | | Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. | | | | MIG M. | |===============================+======================+======================| | 0 Tesla V100-SXM2... On | 00000000:00:09.0 Off | 0 | | N/A 35C P0 59W / 300W | 334MiB / 16384MiB | 0% Default | | | | N/A | +-------------------------------+----------------------+----------------------+ +-----------------------------------------------------------------------------+ | Processes: | | GPU GI CI PID Type Process name GPU Memory | | ID ID Usage | |=============================================================================| +-----------------------------------------------------------------------------+The output shows that the total GPU Memory available inside the Pod is 16384 MiB (the full memory of the Tesla V100 card used in this example). In contrast, if GPU Memory Isolation were enabled, this value would match the requested 4 GiB. This confirms that the configuration is working as expected.
Your application needs to read its allocated GPU Memory limit from the following Environment Variables:
ALIYUN_COM_GPU_MEM_CONTAINER=4 # The amount of GPU Memory available to the Pod. ALIYUN_COM_GPU_MEM_DEV=16 # The total GPU Memory of the physical GPU card.If your application requires the memory allocation as a percentage of the total GPU Memory, you can calculate it by using these Environment Variables with the following formula:
percentage = ALIYUN_COM_GPU_MEM_CONTAINER / ALIYUN_COM_GPU_MEM_DEV = 4 / 16 = 0.25