You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by GitBox <gi...@apache.org> on 2017/12/27 11:26:28 UTC

[GitHub] nitin-maharana commented on a change in pull request #2340: CLOUDSTACK-10106: GPU/vGPU Support on VMware

nitin-maharana commented on a change in pull request #2340: CLOUDSTACK-10106: GPU/vGPU Support on VMware
URL: https://github.com/apache/cloudstack/pull/2340#discussion_r158800362
 
 

 ##########
 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:
   @rhtyd, I didn't get you properly. I guess you are saying to replace the multiple remainingCapacities assignments present in the if..else statement with a single assignment using index variable by matching the grid type. Am I correct?
   
   Note:
   Actually, the reason why I hardcoded those assignments because unlike XenServer, VMware doesn't provide libraries to get the remaining capacities of each vGPU type. To obtain that I used the VM size, which says how many VMs of the particular vGPU type present in the card. Accordingly, it reduces the capacity of each vGPU type(One vGPU type affects the capacity of other vGPU types).

----------------------------------------------------------------
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