cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] rhtyd commented on a change in pull request #2340: CLOUDSTACK-10106: GPU/vGPU Support on VMware
Date Thu, 01 Jan 1970 00:00:00 GMT
rhtyd commented on a change in pull request #2340: CLOUDSTACK-10106: GPU/vGPU Support on VMware
URL: https://github.com/apache/cloudstack/pull/2340#discussion_r158675008
 
 

 ##########
 File path: vmware-base/src/com/cloud/hypervisor/vmware/mo/HostMO.java
 ##########
 @@ -1184,4 +1206,261 @@ public ManagedObjectReference waitForPortGroup(String networkName,
long timeOutM
         }
         return morNetwork;
     }
+
+    public ManagedObjectReference getComputeResourceEnvironmentBrowser() throws Exception
{
+        ManagedObjectReference morParent = getParentMor();
+        ClusterMO clusterMo = new ClusterMO(_context, morParent);
+        return clusterMo.getComputeResourceEnvironmentBrowser();
+    }
+
+    public VirtualMachinePciPassthroughInfo getHostPciDeviceInfo(final String pciDeviceId)
throws Exception {
+        VirtualMachinePciPassthroughInfo matchingPciPassthroughDevice = null;
+        ConfigTarget configTarget = _context.getService().queryConfigTarget(getComputeResourceEnvironmentBrowser(),
_mor);
+        List<VirtualMachinePciPassthroughInfo> pciPassthroughDevices = configTarget.getPciPassthrough();
+        for (VirtualMachinePciPassthroughInfo pciPassthroughDevice : pciPassthroughDevices)
{
+            HostPciDevice hostPciDevice = pciPassthroughDevice.getPciDevice();
+            if (pciDeviceId.equals(hostPciDevice.getId())) {
+                matchingPciPassthroughDevice = pciPassthroughDevice;
+                break;
+            }
+        }
+        return matchingPciPassthroughDevice;
+    }
+
+    public VirtualDevice prepareSharedPciPassthroughDevice(final String vGpuProfile) {
+        s_logger.debug("Preparing shared PCI device");
+        VirtualPCIPassthrough virtualPciPassthrough = new VirtualPCIPassthrough();
+        VirtualPCIPassthroughVmiopBackingInfo virtualPCIPassthroughVmiopBackingInfo = new
VirtualPCIPassthroughVmiopBackingInfo();
+        virtualPCIPassthroughVmiopBackingInfo.setVgpu(vGpuProfile);
+        virtualPciPassthrough.setBacking(virtualPCIPassthroughVmiopBackingInfo);
+        Description description = new Description();
+        description.setLabel("vGPU device");
+        description.setSummary("vGPU type: " + vGpuProfile);
+        virtualPciPassthrough.setDeviceInfo(description);
+        return virtualPciPassthrough;
+    }
+
+    public VirtualDevice prepareDirectPciPassthroughDevice(final VirtualMachinePciPassthroughInfo
hostPciDeviceInfo) {
+        // Ex: pciDeviceId is like "0000:08:00.0" composed of bus,slot,function
+        s_logger.debug("Preparing direct PCI device");
+
+        VirtualPCIPassthrough pciDevice = new VirtualPCIPassthrough();
+        VirtualPCIPassthroughDeviceBackingInfo pciBacking = new VirtualPCIPassthroughDeviceBackingInfo();
+        pciBacking.setId(hostPciDeviceInfo.getPciDevice().getId());
+        pciBacking.setDeviceId(Integer.toHexString(hostPciDeviceInfo.getPciDevice().getDeviceId()));
+        pciBacking.setDeviceName(hostPciDeviceInfo.getPciDevice().getDeviceName());
+        pciBacking.setVendorId(hostPciDeviceInfo.getPciDevice().getVendorId());
+        pciBacking.setSystemId(hostPciDeviceInfo.getSystemId());
+        pciDevice.setBacking(pciBacking);
+        return pciDevice;
+    }
+
+    public String getPciIdForAvailableDirectPciPassthroughDevice() throws Exception {
+        String pciId = "";
+        List<HostGraphicsInfo> hostGraphicsInfos = getHostGraphicsInfo();
+        for (HostGraphicsInfo hostGraphicsInfo : hostGraphicsInfos) {
+            if (GPU.GPUType.direct.toString().equalsIgnoreCase(hostGraphicsInfo.getGraphicsType()))
{
+                List<ManagedObjectReference> vms = hostGraphicsInfo.getVm();
+                if (CollectionUtils.isEmpty(vms)) {
+                    pciId = hostGraphicsInfo.getPciId();
+                    break;
+                }
+            }
+        }
+        return pciId;
+    }
+
+    /**
+     * It updates the info of each vGPU type in the NVidia GRID K1/K2 Card.
+     * @param gpuCapacity (The output is stored in this)
+     * @param groupName - (NVIDIAGRID K1 or NVIDIAGRID K2)
+     * @param countGridKSharedGPUs (Number of Enabled shared GPUs)
+     * @param graphicsInfo (Info regarding the card)
+     * @param sharedPassthruGpuTypes (All the enabled vGPU types)
+     * @param gridKGPUMemory (Video RAM of each GPU in the card)
+     * @throws Exception
+     */
+    private void updateGpuCapacities(final HashMap<String, VgpuTypesInfo> gpuCapacity,
final String groupName, final long countGridKSharedGPUs, final List<HostGraphicsInfo>
graphicsInfo, final List<String> sharedPassthruGpuTypes, final long gridKGPUMemory)
throws Exception {
+        /*
+         * 0 - grid_k100 or grid_k200
+         * 1 - grid_k120q or grid_k220q
+         * 2 - grid_k140q or grid_k240q
+         * 3 - grid_k160q or grid_k260q
+         * 4 - grid_k180q or grid_k280q
+         */
+        final long remainingCapacities[] = new long[5];
+
+        remainingCapacities[0] = 8l * countGridKSharedGPUs;
+        remainingCapacities[1] = 8l * countGridKSharedGPUs;
+        remainingCapacities[2] = 4l * countGridKSharedGPUs;
+        remainingCapacities[3] = 2l * countGridKSharedGPUs;
+        remainingCapacities[4] = countGridKSharedGPUs;
+
+        for (final HostGraphicsInfo graphicInfo : graphicsInfo) {
+            if (graphicInfo.getDeviceName().equals(groupName) && graphicInfo.getGraphicsType().equals("shared"))
{
+                if (CollectionUtils.isNotEmpty(graphicInfo.getVm())) {
+                    String vgpuType = "None";
+
+                    for (ManagedObjectReference mor : graphicInfo.getVm()) {
+                        final VirtualMachineMO vmMo = new VirtualMachineMO(_context, mor);
+
+                        if (vgpuType.equals("None") && vmMo != null && vmMo.getConfigInfo()
!= null && vmMo.getConfigInfo().getHardware() != null) {
+                            final List<VirtualDevice> devices = vmMo.getConfigInfo().getHardware().getDevice();
+
+                            for (VirtualDevice device : devices) {
+                                if (device instanceof VirtualPCIPassthrough) {
+                                    if (device.getBacking() != null && (device.getBacking()
instanceof VirtualPCIPassthroughVmiopBackingInfo)) {
+                                        final VirtualPCIPassthroughVmiopBackingInfo backingInfo
= (VirtualPCIPassthroughVmiopBackingInfo) device.getBacking();
+
+                                        if (backingInfo.getVgpu() != null) {
+                                            vgpuType = backingInfo.getVgpu();
+                                            break;
+                                        }
+                                    }
+                                }
+                            }
+                        }
+                    }
+
+                    // If GRID K1, then search for only K1 vGPU types. Same for GRID K2.
+                    // The remaining capacity of one type affects other vGPU type capacity.
+                    // Each GPU should always contain one type of vGPU VMs.
+                    if ((groupName.equals("NVIDIAGRID K1") && vgpuType.equals("grid_k100"))
|| (groupName.equals("NVIDIAGRID K2") && vgpuType.equals("grid_k200"))) {
 
 Review comment:
   @nitin-maharana can you refactor this code by assigning the groupName against an index
where `graphicInfo.getVm().size()` should be used instead of static/hard-coded `remainingCapacities`
values.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message