Skip to content

Feature: Add support for GPU with KVM hosts #11143

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

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ jobs:
smoke/test_vm_deployment_planner
smoke/test_vm_strict_host_tags
smoke/test_vm_schedule
smoke/test_deploy_vgpu_enabled_vm
smoke/test_vm_life_cycle
smoke/test_vm_lifecycle_unmanage_import
smoke/test_vm_snapshot_kvm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,15 @@ public class AgentProperties{
*/
public static final Property<String> AGENT_HOOKS_LIBVIRT_VM_XML_TRANSFORMER_SCRIPT = new Property<>("agent.hooks.libvirt_vm_xml_transformer.script", "libvirt-vm-xml-transformer.groovy");

/**
* This property is used with the agent.hooks.basedir property to define the Libvirt VM XML transformer shell script.<br>
* The shell script is used to execute the Libvirt VM XML transformer script.<br>
* For more information see the agent.properties file.<br>
* Data type: String.<br>
* Default value: <code>libvirt-vm-xml-transformer.sh</code>
*/
public static final Property<String> AGENT_HOOKS_LIBVIRT_VM_XML_TRANSFORMER_SHELL_SCRIPT = new Property<>("agent.hooks.libvirt_vm_xml_transformer.shell_script", "libvirt-vm-xml-transformer.sh");

/**
* This property is used with the agent.hooks.basedir and agent.hooks.libvirt_vm_xml_transformer.script properties to define the Libvirt VM XML transformer method.<br>
* Libvirt XML transformer hook does XML-to-XML transformation.<br>
Expand All @@ -233,6 +242,15 @@ public class AgentProperties{
*/
public static final Property<String> AGENT_HOOKS_LIBVIRT_VM_ON_START_SCRIPT = new Property<>("agent.hooks.libvirt_vm_on_start.script", "libvirt-vm-state-change.groovy");

/**
* This property is used with the agent.hooks.basedir property to define the Libvirt VM on start shell script.<br>
* The shell script is used to execute the Libvirt VM on start script.<br>
* For more information see the agent.properties file.<br>
* Data type: String.<br>
* Default value: <code>libvirt-vm-state-change.sh</code>
*/
public static final Property<String> AGENT_HOOKS_LIBVIRT_VM_ON_START_SHELL_SCRIPT = new Property<>("agent.hooks.libvirt_vm_on_start.shell_script", "libvirt-vm-state-change.sh");

/**
* This property is used with the agent.hooks.basedir and agent.hooks.libvirt_vm_on_start.script properties to define the Libvirt VM on start method.<br>
* The hook is called right after Libvirt successfully launched the VM.<br>
Expand All @@ -252,6 +270,15 @@ public class AgentProperties{
*/
public static final Property<String> AGENT_HOOKS_LIBVIRT_VM_ON_STOP_SCRIPT = new Property<>("agent.hooks.libvirt_vm_on_stop.script", "libvirt-vm-state-change.groovy");

/**
* This property is used with the agent.hooks.basedir property to define the Libvirt VM on stop shell script.<br>
* The shell script is used to execute the Libvirt VM on stop script.<br>
* For more information see the agent.properties file.<br>
* Data type: String.<br>
* Default value: <code>libvirt-vm-state-change.sh</code>
*/
public static final Property<String> AGENT_HOOKS_LIBVIRT_VM_ON_STOP_SHELL_SCRIPT = new Property<>("agent.hooks.libvirt_vm_on_stop.shell_script", "libvirt-vm-state-change.sh");

/**
* This property is used with the agent.hooks.basedir and agent.hooks.libvirt_vm_on_stop.script properties to define the Libvirt VM on stop method.<br>
* The hook is called right after libvirt successfully stopped the VM.<br>
Expand Down
164 changes: 162 additions & 2 deletions api/src/main/java/com/cloud/agent/api/VgpuTypesInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,32 @@
// specific language governing permissions and limitations
// under the License.
package com.cloud.agent.api;

import org.apache.cloudstack.gpu.GpuDevice;

public class VgpuTypesInfo {

private boolean passthroughEnabled = true;
private GpuDevice.DeviceType deviceType;
private String parentBusAddress;
private String busAddress;
private String numaNode;
private String pciRoot;
private String deviceId;
private String deviceName;
private String vendorId;
private String vendorName;
private String modelName;
private String groupName;
private String vmName;
private Long maxHeads;
private Long videoRam;
private Long maxResolutionX;
private Long maxResolutionY;
private Long maxVgpuPerGpu;
private Long remainingCapacity;
private Long maxCapacity;
private boolean display = false;

public String getModelName() {
return modelName;
Expand All @@ -39,22 +54,42 @@ public Long getVideoRam() {
return videoRam;
}

public void setVideoRam(Long videoRam) {
this.videoRam = videoRam;
}

public Long getMaxHeads() {
return maxHeads;
}

public void setMaxHeads(Long maxHeads) {
this.maxHeads = maxHeads;
}

public Long getMaxResolutionX() {
return maxResolutionX;
}

public void setMaxResolutionX(Long maxResolutionX) {
this.maxResolutionX = maxResolutionX;
}

public Long getMaxResolutionY() {
return maxResolutionY;
}

public void setMaxResolutionY(Long maxResolutionY) {
this.maxResolutionY = maxResolutionY;
}

public Long getMaxVpuPerGpu() {
return maxVgpuPerGpu;
}

public void setMaxVgpuPerGpu(Long maxVgpuPerGpu) {
this.maxVgpuPerGpu = maxVgpuPerGpu;
}

public Long getRemainingCapacity() {
return remainingCapacity;
}
Expand All @@ -71,8 +106,133 @@ public void setMaxVmCapacity(Long maxCapacity) {
this.maxCapacity = maxCapacity;
}

public VgpuTypesInfo(String groupName, String modelName, Long videoRam, Long maxHeads, Long maxResolutionX, Long maxResolutionY, Long maxVgpuPerGpu,
Long remainingCapacity, Long maxCapacity) {
public boolean isPassthroughEnabled() {
return passthroughEnabled;
}

public void setPassthroughEnabled(boolean passthroughEnabled) {
this.passthroughEnabled = passthroughEnabled;
}

public GpuDevice.DeviceType getDeviceType() {
return deviceType;
}

public void setDeviceType(GpuDevice.DeviceType deviceType) {
this.deviceType = deviceType;
}

public String getParentBusAddress() {
return parentBusAddress;
}

public void setParentBusAddress(String parentBusAddress) {
this.parentBusAddress = parentBusAddress;
}

public String getBusAddress() {
return busAddress;
}

public void setBusAddress(String busAddress) {
this.busAddress = busAddress;
}

public String getNumaNode() {
return numaNode;
}

public void setNumaNode(String numaNode) {
this.numaNode = numaNode;
}

public String getPciRoot() {
return pciRoot;
}

public void setPciRoot(String pciRoot) {
this.pciRoot = pciRoot;
}

public String getDeviceId() {
return deviceId;
}

public void setDeviceId(String deviceId) {
this.deviceId = deviceId;
}

public String getDeviceName() {
return deviceName;
}

public void setDeviceName(String deviceName) {
this.deviceName = deviceName;
}

public String getVendorId() {
return vendorId;
}

public void setVendorId(String vendorId) {
this.vendorId = vendorId;
}

public String getVendorName() {
return vendorName;
}

public void setVendorName(String vendorName) {
this.vendorName = vendorName;
}

public String getVmName() {
return vmName;
}

public void setVmName(String vmName) {
this.vmName = vmName;
}

public boolean isDisplay() {
return display;
}

public void setDisplay(boolean display) {
this.display = display;
}

public VgpuTypesInfo(GpuDevice.DeviceType deviceType, String groupName, String modelName, String busAddress,
String vendorId, String vendorName, String deviceId, String deviceName, String numaNode, String pciRoot
) {
this.deviceType = deviceType;
this.groupName = groupName;
this.modelName = modelName;
this.busAddress = busAddress;
this.deviceId = deviceId;
this.deviceName = deviceName;
this.vendorId = vendorId;
this.vendorName = vendorName;
this.numaNode = numaNode;
this.pciRoot = pciRoot;
}

public VgpuTypesInfo(GpuDevice.DeviceType deviceType, String groupName, String modelName, String busAddress,
String vendorId, String vendorName, String deviceId, String deviceName
) {
this.deviceType = deviceType;
this.groupName = groupName;
this.modelName = modelName;
this.busAddress = busAddress;
this.deviceId = deviceId;
this.deviceName = deviceName;
this.vendorId = vendorId;
this.vendorName = vendorName;
}

public VgpuTypesInfo(String groupName, String modelName, Long videoRam, Long maxHeads, Long maxResolutionX,
Long maxResolutionY, Long maxVgpuPerGpu, Long remainingCapacity, Long maxCapacity
) {
this.groupName = groupName;
this.modelName = modelName;
this.videoRam = videoRam;
Expand Down
33 changes: 32 additions & 1 deletion api/src/main/java/com/cloud/agent/api/to/GPUDeviceTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,33 @@
// under the License.
package com.cloud.agent.api.to;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import com.cloud.agent.api.VgpuTypesInfo;

public class GPUDeviceTO {

private String gpuGroup;
private String vgpuType;
private int gpuCount;
private HashMap<String, HashMap<String, VgpuTypesInfo>> groupDetails = new HashMap<String, HashMap<String, VgpuTypesInfo>>();
private List<VgpuTypesInfo> gpuDevices = new ArrayList<>();

public GPUDeviceTO( String gpuGroup, String vgpuType, HashMap<String, HashMap<String, VgpuTypesInfo>> groupDetails) {
public GPUDeviceTO(String gpuGroup, String vgpuType, int gpuCount,
HashMap<String, HashMap<String, VgpuTypesInfo>> groupDetails,
List<VgpuTypesInfo> gpuDevices) {
this.gpuGroup = gpuGroup;
this.vgpuType = vgpuType;
this.groupDetails = groupDetails;
this.gpuCount = gpuCount;
this.gpuDevices = gpuDevices;

}

public GPUDeviceTO(String gpuGroup, String vgpuType,
HashMap<String, HashMap<String, VgpuTypesInfo>> groupDetails) {
this.gpuGroup = gpuGroup;
this.vgpuType = vgpuType;
this.groupDetails = groupDetails;
Expand All @@ -48,6 +64,14 @@ public void setVgpuType(String vgpuType) {
this.vgpuType = vgpuType;
}

public int getGpuCount() {
return gpuCount;
}

public void setGpuCount(int gpuCount) {
this.gpuCount = gpuCount;
}

public HashMap<String, HashMap<String, VgpuTypesInfo>> getGroupDetails() {
return groupDetails;
}
Expand All @@ -56,4 +80,11 @@ public void setGroupDetails(HashMap<String, HashMap<String, VgpuTypesInfo>> grou
this.groupDetails = groupDetails;
}

public List<VgpuTypesInfo> getGpuDevices() {
return gpuDevices;
}

public void setGpuDevices(List<VgpuTypesInfo> gpuDevices) {
this.gpuDevices = gpuDevices;
}
}
2 changes: 1 addition & 1 deletion api/src/main/java/com/cloud/capacity/Capacity.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public interface Capacity extends InternalIdentity, Identity {
public static final short CAPACITY_TYPE_DIRECT_ATTACHED_PUBLIC_IP = 8;
public static final short CAPACITY_TYPE_LOCAL_STORAGE = 9;
public static final short CAPACITY_TYPE_VIRTUAL_NETWORK_IPV6_SUBNET = 10;
public static final short CAPACITY_TYPE_GPU = 19;
public static final short CAPACITY_TYPE_GPU = 11;

public static final short CAPACITY_TYPE_CPU_CORE = 90;

Expand Down
3 changes: 2 additions & 1 deletion api/src/main/java/com/cloud/configuration/Resource.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ enum ResourceType { // All storage type resources are allocated_storage and not
backup("backup", 12),
backup_storage("backup_storage", 13),
bucket("bucket", 14),
object_storage("object_storage", 15);
object_storage("object_storage", 15),
gpu("gpu", 16);

private String name;
private int ordinal;
Expand Down
Loading
Loading