[ 
https://issues.apache.org/jira/browse/CLOUDSTACK-10106?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16303580#comment-16303580
 ] 

ASF GitHub Bot commented on CLOUDSTACK-10106:
---------------------------------------------

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_r158675087
 
 

 ##########
 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"))) {
+                        remainingCapacities[0] -= 
((long)graphicInfo.getVm().size());
+                        remainingCapacities[1] -= 8l;
+                        remainingCapacities[2] -= 4l;
+                        remainingCapacities[3] -= 2l;
+                        remainingCapacities[4] -= 1l;
+                    } else if ((groupName.equals("NVIDIAGRID K1") && 
vgpuType.equals("grid_k120q")) || (groupName.equals("NVIDIAGRID K2") && 
vgpuType.equals("grid_k220q"))) {
+                        remainingCapacities[0] -= 8l;
+                        remainingCapacities[1] -= ((long) 
graphicInfo.getVm().size());
+                        remainingCapacities[2] -= 4l;
+                        remainingCapacities[3] -= 2l;
+                        remainingCapacities[4] -= 1l;
+                    } else if ((groupName.equals("NVIDIAGRID K1") && 
vgpuType.equals("grid_k140q")) || (groupName.equals("NVIDIAGRID K2") && 
vgpuType.equals("grid_k240q"))) {
+                        remainingCapacities[0] -= 8l;
+                        remainingCapacities[1] -= 8l;
+                        remainingCapacities[2] -= ((long) 
graphicInfo.getVm().size());
+                        remainingCapacities[3] -= 2l;
+                        remainingCapacities[4] -= 1l;
+                    } else if ((groupName.equals("NVIDIAGRID K1") && 
vgpuType.equals("grid_k160q")) || (groupName.equals("NVIDIAGRID K2") && 
vgpuType.equals("grid_k260q"))) {
+                        remainingCapacities[0] -= 8l;
+                        remainingCapacities[1] -= 8l;
+                        remainingCapacities[2] -= 4l;
+                        remainingCapacities[3] -= 
((long)graphicInfo.getVm().size());
+                        remainingCapacities[4] -= 1l;
+                    } else if ((groupName.equals("NVIDIAGRID K1") && 
vgpuType.equals("grid_k180q")) || (groupName.equals("NVIDIAGRID K2") && 
vgpuType.equals("grid_k280q"))) {
+                        remainingCapacities[0] -= 8l;
+                        remainingCapacities[1] -= 8l;
+                        remainingCapacities[2] -= 4l;
+                        remainingCapacities[3] -= 2l;
+                        remainingCapacities[4] -= 
((long)graphicInfo.getVm().size());
+                    }
+                }
+            }
+        }
+
+        //Pattern.matches("grid_k100|grid_k1[2468]0[q]", gpuType)
+        for (final String gpuType : sharedPassthruGpuTypes) {
+            if ((groupName.equals("NVIDIAGRID K1") && 
gpuType.equals("grid_k100")) || (groupName.equals("NVIDIAGRID K2") && 
gpuType.equals("grid_k200"))) {
 
 Review comment:
   @nitin-maharana it's probably worth exploring refactoring each supported gfx 
card type as it's own class wrapping the behaviour of what gpuCapacity to put?

----------------------------------------------------------------
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:
us...@infra.apache.org


> GPU/vGPU Support on VMWare
> --------------------------
>
>                 Key: CLOUDSTACK-10106
>                 URL: https://issues.apache.org/jira/browse/CLOUDSTACK-10106
>             Project: CloudStack
>          Issue Type: New Feature
>      Security Level: Public(Anyone can view this level - this is the 
> default.) 
>          Components: API, UI, VMware
>    Affects Versions: 4.11.0.0
>            Reporter: Nitin Kumar Maharana
>              Labels: VMWARE
>             Fix For: 4.11.0.0
>
>
> VMware has added support for NVIDIA GRID K1 and NVIDIA GRID K2 cards as well 
> as NVIDIA Tesla M6 and Tesla M60 cards. This feature allows CloudStack VMs on 
> ESXi hosts to use the GPU cards connected to it. Currently, it supports only 
> NVIDIA GRID K1 and K2 cards for CloudStack VMs.
> Feature Specification: 
> https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=74681765



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to