Commit f61781a8 authored by Ahmad Siavashi's avatar Ahmad Siavashi

VgpuScheduler revised

parent 34be0190
......@@ -32,7 +32,7 @@ import org.cloudbus.cloudsim.gpu.Pgpu;
import org.cloudbus.cloudsim.gpu.Vgpu;
import org.cloudbus.cloudsim.gpu.VgpuScheduler;
import org.cloudbus.cloudsim.gpu.VgpuSchedulerFairShare;
import org.cloudbus.cloudsim.gpu.VgpuTags;
import org.cloudbus.cloudsim.gpu.GridVgpuTags;
import org.cloudbus.cloudsim.gpu.VideoCard;
import org.cloudbus.cloudsim.gpu.VideoCardTags;
import org.cloudbus.cloudsim.gpu.allocation.VideoCardAllocationPolicy;
......@@ -227,7 +227,7 @@ public class CloudSimGpuExample1 {
// Create GpuTask Scheduler
GpuTaskSchedulerLeftover gpuTaskScheduler = new GpuTaskSchedulerLeftover();
// Create a Vgpu
Vgpu vgpu = VgpuTags.getK180Q(vgpuId, gpuTaskScheduler);
Vgpu vgpu = GridVgpuTags.getK180Q(vgpuId, gpuTaskScheduler);
vm.setVgpu(vgpu);
return vm;
}
......@@ -397,7 +397,7 @@ public class CloudSimGpuExample1 {
at.addRule();
if (gpuTask.getTaskStatus() == GpuTask.FINISHED) {
at.addRow(gpuTask.getTaskId(), gpuTask.getCloudlet().getCloudletId(), "SUCCESS",
VgpuTags.getVgpuTypeString(
GridVgpuTags.getVgpuTypeString(
((GpuVm) VmList.getById(vmlist, gpuTask.getCloudlet().getVmId())).getVgpu().getType()),
dft.format(gpuTask.getActualGPUTime()).toString(),
dft.format(gpuTask.getExecStartTime()).toString(),
......
......@@ -33,7 +33,7 @@ import org.cloudbus.cloudsim.gpu.ResGpuTask;
import org.cloudbus.cloudsim.gpu.Vgpu;
import org.cloudbus.cloudsim.gpu.VgpuScheduler;
import org.cloudbus.cloudsim.gpu.VgpuSchedulerFairShare;
import org.cloudbus.cloudsim.gpu.VgpuTags;
import org.cloudbus.cloudsim.gpu.GridVgpuTags;
import org.cloudbus.cloudsim.gpu.VideoCard;
import org.cloudbus.cloudsim.gpu.VideoCardTags;
import org.cloudbus.cloudsim.gpu.allocation.VideoCardAllocationPolicy;
......@@ -233,7 +233,7 @@ public class CloudSimGpuExample2 {
// Create GpuTask Scheduler
GpuTaskSchedulerLeftover gpuTaskScheduler = new InterferenceGpuTaskSchedulerLeftover(interferenceModel);
// Create a Vgpu
Vgpu vgpu = VgpuTags.getK280Q(vgpuId, gpuTaskScheduler);
Vgpu vgpu = GridVgpuTags.getK280Q(vgpuId, gpuTaskScheduler);
vm.setVgpu(vgpu);
return vm;
}
......@@ -403,7 +403,7 @@ public class CloudSimGpuExample2 {
at.addRule();
if (gpuTask.getTaskStatus() == GpuTask.FINISHED) {
at.addRow(gpuTask.getTaskId(), gpuTask.getCloudlet().getCloudletId(), "SUCCESS",
VgpuTags.getVgpuTypeString(
GridVgpuTags.getVgpuTypeString(
((GpuVm) VmList.getById(vmlist, gpuTask.getCloudlet().getVmId())).getVgpu().getType()),
dft.format(gpuTask.getActualGPUTime()).toString(),
dft.format(gpuTask.getExecStartTime()).toString(),
......
......@@ -32,7 +32,7 @@ import org.cloudbus.cloudsim.gpu.Pgpu;
import org.cloudbus.cloudsim.gpu.ResGpuTask;
import org.cloudbus.cloudsim.gpu.Vgpu;
import org.cloudbus.cloudsim.gpu.VgpuScheduler;
import org.cloudbus.cloudsim.gpu.VgpuTags;
import org.cloudbus.cloudsim.gpu.GridVgpuTags;
import org.cloudbus.cloudsim.gpu.VideoCard;
import org.cloudbus.cloudsim.gpu.VideoCardTags;
import org.cloudbus.cloudsim.gpu.allocation.VideoCardAllocationPolicy;
......@@ -171,8 +171,8 @@ public class CloudSimGpuExample3 {
interferenceModel);
// Create a Vgpu
int vgpuId = i;
Vgpu vgpu = i < 1 ? VgpuTags.getK280Q(vgpuId, gpuTaskScheduler)
: VgpuTags.getK260Q(vgpuId, gpuTaskScheduler);
Vgpu vgpu = i < 1 ? GridVgpuTags.getK280Q(vgpuId, gpuTaskScheduler)
: GridVgpuTags.getK260Q(vgpuId, gpuTaskScheduler);
vm.setVgpu(vgpu);
vmlist.add(vm);
}
......@@ -376,7 +376,7 @@ public class CloudSimGpuExample3 {
at.addRule();
if (gpuTask.getTaskStatus() == GpuTask.FINISHED) {
at.addRow(gpuTask.getTaskId(), gpuTask.getCloudlet().getCloudletId(), "SUCCESS",
VgpuTags.getVgpuTypeString(
GridVgpuTags.getVgpuTypeString(
((GpuVm) VmList.getById(vmlist, gpuTask.getCloudlet().getVmId())).getVgpu().getType()),
dft.format(gpuTask.getActualGPUTime()).toString(),
dft.format(gpuTask.getExecStartTime()).toString(),
......
......@@ -30,7 +30,7 @@ import org.cloudbus.cloudsim.gpu.GpuVmTags;
import org.cloudbus.cloudsim.gpu.Pgpu;
import org.cloudbus.cloudsim.gpu.Vgpu;
import org.cloudbus.cloudsim.gpu.VgpuScheduler;
import org.cloudbus.cloudsim.gpu.VgpuTags;
import org.cloudbus.cloudsim.gpu.GridVgpuTags;
import org.cloudbus.cloudsim.gpu.VideoCard;
import org.cloudbus.cloudsim.gpu.VideoCardTags;
import org.cloudbus.cloudsim.gpu.allocation.VideoCardAllocationPolicy;
......@@ -225,7 +225,7 @@ public class CloudSimGpuExample4 {
// Create GpuTask Scheduler
GpuTaskSchedulerLeftover gpuTaskScheduler = new GpuTaskSchedulerLeftover();
// Create a Vgpu
Vgpu vgpu = VgpuTags.getK180Q(vgpuId, gpuTaskScheduler);
Vgpu vgpu = GridVgpuTags.getK180Q(vgpuId, gpuTaskScheduler);
vm.setVgpu(vgpu);
return vm;
}
......@@ -405,7 +405,7 @@ public class CloudSimGpuExample4 {
at.addRule();
if (gpuTask.getTaskStatus() == GpuTask.FINISHED) {
at.addRow(gpuTask.getTaskId(), gpuTask.getCloudlet().getCloudletId(), "SUCCESS",
VgpuTags.getVgpuTypeString(
GridVgpuTags.getVgpuTypeString(
((GpuVm) VmList.getById(vmlist, gpuTask.getCloudlet().getVmId())).getVgpu().getType()),
dft.format(gpuTask.getActualGPUTime()).toString(),
dft.format(gpuTask.getExecStartTime()).toString(),
......
......@@ -30,7 +30,7 @@ import org.cloudbus.cloudsim.gpu.GpuVmTags;
import org.cloudbus.cloudsim.gpu.Pgpu;
import org.cloudbus.cloudsim.gpu.Vgpu;
import org.cloudbus.cloudsim.gpu.VgpuScheduler;
import org.cloudbus.cloudsim.gpu.VgpuTags;
import org.cloudbus.cloudsim.gpu.GridVgpuTags;
import org.cloudbus.cloudsim.gpu.VideoCard;
import org.cloudbus.cloudsim.gpu.VideoCardTags;
import org.cloudbus.cloudsim.gpu.allocation.VideoCardAllocationPolicy;
......@@ -225,7 +225,7 @@ public class CloudSimGpuExample5 {
// Create GpuTask Scheduler
GpuTaskSchedulerLeftover gpuTaskScheduler = new GpuTaskSchedulerLeftover();
// Create a Vgpu
Vgpu vgpu = VgpuTags.getK180Q(vgpuId, gpuTaskScheduler);
Vgpu vgpu = GridVgpuTags.getK180Q(vgpuId, gpuTaskScheduler);
vm.setVgpu(vgpu);
return vm;
}
......@@ -428,7 +428,7 @@ public class CloudSimGpuExample5 {
at.addRule();
if (gpuTask.getTaskStatus() == GpuTask.FINISHED) {
at.addRow(gpuTask.getTaskId(), gpuTask.getCloudlet().getCloudletId(), "SUCCESS",
VgpuTags.getVgpuTypeString(
GridVgpuTags.getVgpuTypeString(
((GpuVm) VmList.getById(vmlist, gpuTask.getCloudlet().getVmId())).getVgpu().getType()),
dft.format(gpuTask.getActualGPUTime()).toString(),
dft.format(gpuTask.getExecStartTime()).toString(),
......
......@@ -49,37 +49,37 @@ public class GpuVmTags {
mips = GpuHostTags.DUAL_INTEL_XEON_E5_2690_V4_PE_MIPS;
pesNumber = 8;
ram = 16;
vgpu = VgpuTags.getK280Q(vgpuId, gpuTaskScheduler);
vgpu = GridVgpuTags.getK280Q(vgpuId, gpuTaskScheduler);
break;
case VCPU_4_E5_2620_V3_RAM_16_K180Q:
mips = GpuHostTags.DUAL_INTEL_XEON_E5_2620_V3_PE_MIPS;
pesNumber = 4;
ram = 16;
vgpu = VgpuTags.getK180Q(vgpuId, gpuTaskScheduler);
vgpu = GridVgpuTags.getK180Q(vgpuId, gpuTaskScheduler);
break;
case VCPU_4_E5_2090_V4_RAM_8_K260Q:
mips = GpuHostTags.DUAL_INTEL_XEON_E5_2690_V4_PE_MIPS;
pesNumber = 4;
ram = 8;
vgpu = VgpuTags.getK260Q(vgpuId, gpuTaskScheduler);
vgpu = GridVgpuTags.getK260Q(vgpuId, gpuTaskScheduler);
break;
case VCPU_2_E5_2620_V3_RAM_8_K160Q:
mips = GpuHostTags.DUAL_INTEL_XEON_E5_2620_V3_PE_MIPS;
pesNumber = 2;
ram = 8;
vgpu = VgpuTags.getK160Q(vgpuId, gpuTaskScheduler);
vgpu = GridVgpuTags.getK160Q(vgpuId, gpuTaskScheduler);
break;
case VCPU_2_E5_2090_V4_RAM_4_K240Q:
mips = GpuHostTags.DUAL_INTEL_XEON_E5_2690_V4_PE_MIPS;
pesNumber = 2;
ram = 4;
vgpu = VgpuTags.getK240Q(vgpuId, gpuTaskScheduler);
vgpu = GridVgpuTags.getK240Q(vgpuId, gpuTaskScheduler);
break;
case VCPU_2_E5_2620_V3_RAM_4_K140Q:
mips = GpuHostTags.DUAL_INTEL_XEON_E5_2620_V3_PE_MIPS;
pesNumber = 2;
ram = 4;
vgpu = VgpuTags.getK140Q(vgpuId, gpuTaskScheduler);
vgpu = GridVgpuTags.getK140Q(vgpuId, gpuTaskScheduler);
break;
default:
System.err.println("[!] Unknown GpuVm Type: " + type);
......
......@@ -11,7 +11,7 @@ package org.cloudbus.cloudsim.gpu;
*
*/
public class VgpuTags {
public class GridVgpuTags {
public final static int VGPU_CUSTOM = -1;
......@@ -221,7 +221,7 @@ public class VgpuTags {
/**
* Singleton class (cannot be instantiated)
*/
private VgpuTags() {
private GridVgpuTags() {
}
}
......@@ -9,7 +9,7 @@ import java.util.Map.Entry;
import org.cloudbus.cloudsim.Log;
import org.cloudbus.cloudsim.Pe;
import org.cloudbus.cloudsim.gpu.selection.PgpuSelectionPolicy;
import org.cloudbus.cloudsim.gpu.util.VgpuUtil;
import org.cloudbus.cloudsim.gpu.util.GridVgpuUtil;
/**
* VgpuScheduler is an abstract class that represents the policy used by a
......@@ -91,25 +91,6 @@ public abstract class VgpuScheduler {
*/
public abstract boolean isSuitable(Vgpu vgpu);
/**
* Checks whether the vgpu type is supported by this video card type or not.
*
* @param vgpu
* the vgpu
* @return $true if the video card supports the vgpu type.
*/
public boolean isVideoCardSuitableForVgpu(Vgpu vgpu) {
if (!VgpuUtil.isVideoCardSuitable(getVideoCardType(), vgpu.getType())) {
return false;
}
for (Entry<Pgpu, List<Vgpu>> entry : getPgpuVgpuMap().entrySet()) {
if (VgpuUtil.isPgpuSuitable(entry, vgpu)) {
return true;
}
}
return false;
}
/**
* Releases PEs allocated to a {@link Vgpu}. After that, the PEs may be used on
* demand by other Vgpus.
......
......@@ -6,11 +6,13 @@ import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.Predicate;
import org.cloudbus.cloudsim.Pe;
import org.cloudbus.cloudsim.gpu.selection.PgpuSelectionPolicy;
import org.cloudbus.cloudsim.gpu.util.GridVgpuUtil;
import org.cloudbus.cloudsim.lists.PeList;
import org.cloudbus.cloudsim.util.MathUtil;
......@@ -43,6 +45,54 @@ public class VgpuSchedulerFairShare extends VgpuSchedulerTimeShared {
setRequestedMipsMap(new HashMap<Vgpu, List<Double>>());
}
/**
* Checks whether the vgpu type is supported by this video card type or not.
*
* @param vgpu
* the vgpu
* @return $true if the video card supports the vgpu type.
*/
protected boolean isVideoCardSuitableForVgpu(Vgpu vgpu) {
if (!GridVgpuUtil.isVideoCardSuitable(getVideoCardType(), vgpu.getType())) {
return false;
}
for (Entry<Pgpu, List<Vgpu>> entry : getPgpuVgpuMap().entrySet()) {
if (GridVgpuUtil.isPgpuSuitable(entry, vgpu)) {
return true;
}
}
return false;
}
@SuppressWarnings("unchecked")
@Override
public boolean isSuitable(final Vgpu vgpu) {
if (!isVideoCardSuitableForVgpu(vgpu)) {
return false;
}
final List<Double> mipsShare = vgpu.getCurrentRequestedMips();
final int gddramShare = vgpu.getCurrentRequestedGddram();
final long bwShare = vgpu.getCurrentRequestedBw();
List<Pgpu> candidates = (List<Pgpu>) CollectionUtils.select(getPgpuList(), new Predicate() {
@Override
public boolean evaluate(Object arg) {
Pgpu pgpu = (Pgpu) arg;
if (!pgpu.getGddramProvisioner().isSuitableForVgpu(vgpu, gddramShare)
|| !pgpu.getBwProvisioner().isSuitableForVgpu(vgpu, bwShare)) {
return false;
}
if (pgpu.getPeList().size() < mipsShare.size()) {
return false;
}
return true;
}
});
if (candidates.isEmpty()) {
return false;
}
return true;
}
@Override
@SuppressWarnings("unchecked")
public boolean allocatePgpuForVgpu(final Vgpu vgpu, final List<Double> mipsShare, final int gddramShare,
......@@ -85,8 +135,11 @@ public class VgpuSchedulerFairShare extends VgpuSchedulerTimeShared {
/**
* Rescales mips share of resident vgpus whenever a vgpu enters or leaves.
*
* @param pgpu the pgpu to redistribute the mips share of its resident vgpus
* @param mipsChange the amount of mips that has been changed in the pgpu; either added or removed.
* @param pgpu
* the pgpu to redistribute the mips share of its resident vgpus
* @param mipsChange
* the amount of mips that has been changed in the pgpu; either added
* or removed.
*/
protected void redistributeMipsDueToOverSubscription(final Pgpu pgpu, double mipsChange) {
// calculating the scaling factor
......@@ -156,35 +209,6 @@ public class VgpuSchedulerFairShare extends VgpuSchedulerTimeShared {
redistributeMipsDueToOverSubscription(pgpu, totalMipsChange);
}
@SuppressWarnings("unchecked")
@Override
public boolean isSuitable(final Vgpu vgpu) {
if (!isVideoCardSuitableForVgpu(vgpu)) {
return false;
}
final List<Double> mipsShare = vgpu.getCurrentRequestedMips();
final int gddramShare = vgpu.getCurrentRequestedGddram();
final long bwShare = vgpu.getCurrentRequestedBw();
List<Pgpu> candidates = (List<Pgpu>) CollectionUtils.select(getPgpuList(), new Predicate() {
@Override
public boolean evaluate(Object arg) {
Pgpu pgpu = (Pgpu) arg;
if (!pgpu.getGddramProvisioner().isSuitableForVgpu(vgpu, gddramShare)
|| !pgpu.getBwProvisioner().isSuitableForVgpu(vgpu, bwShare)) {
return false;
}
if (pgpu.getPeList().size() < mipsShare.size()) {
return false;
}
return true;
}
});
if (candidates.isEmpty()) {
return false;
}
return true;
}
/**
* @return the requestedMipsMap
*/
......
......@@ -4,12 +4,14 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map.Entry;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.Predicate;
import org.cloudbus.cloudsim.Pe;
import org.cloudbus.cloudsim.Vm;
import org.cloudbus.cloudsim.gpu.selection.PgpuSelectionPolicy;
import org.cloudbus.cloudsim.gpu.util.GridVgpuUtil;
/**
* VgpuSchedulerSpaceShared is a vgpu allocation policy that allocates one or
......@@ -37,6 +39,80 @@ public class VgpuSchedulerSpaceShared extends VgpuScheduler {
super(videoCardType, pgpuList, pgpuSelectionPolicy);
}
/**
* Checks whether the vgpu type is supported by this video card type or not.
*
* @param vgpu
* the vgpu
* @return $true if the video card supports the vgpu type.
*/
protected boolean isVideoCardSuitableForVgpu(Vgpu vgpu) {
if (!GridVgpuUtil.isVideoCardSuitable(getVideoCardType(), vgpu.getType())) {
return false;
}
for (Entry<Pgpu, List<Vgpu>> entry : getPgpuVgpuMap().entrySet()) {
if (GridVgpuUtil.isPgpuSuitable(entry, vgpu)) {
return true;
}
}
return false;
}
@SuppressWarnings("unchecked")
@Override
public boolean isSuitable(final Vgpu vgpu) {
if (!isVideoCardSuitableForVgpu(vgpu)) {
return false;
}
final List<Double> mipsShare = vgpu.getCurrentRequestedMips();
final int gddramShare = vgpu.getCurrentRequestedGddram();
final long bwShare = vgpu.getCurrentRequestedBw();
List<Pgpu> candidates = (List<Pgpu>) CollectionUtils.select(getPgpuList(), new Predicate() {
@Override
public boolean evaluate(Object arg) {
Pgpu pgpu = (Pgpu) arg;
if (!pgpu.getGddramProvisioner().isSuitableForVgpu(vgpu, gddramShare)
|| !pgpu.getBwProvisioner().isSuitableForVgpu(vgpu, bwShare)) {
return false;
}
List<Pe> pgpuPes = pgpu.getPeList();
int freePes = CollectionUtils.countMatches(pgpuPes, new Predicate() {
@Override
public boolean evaluate(Object arg) {
Pe pe = (Pe) arg;
if (pe.getPeProvisioner().getTotalAllocatedMips() == 0) {
return true;
}
return false;
}
});
if (freePes < mipsShare.size()) {
return false;
}
// PEs in the pgpu are sorted according to their
// available mips
Collections.sort(pgpuPes, Collections.reverseOrder(new Comparator<Pe>() {
public int compare(Pe pe1, Pe pe2) {
return Double.compare(pe1.getPeProvisioner().getAvailableMips(),
pe2.getPeProvisioner().getAvailableMips());
}
}));
for (int i = 0; i < mipsShare.size(); i++) {
if (mipsShare.get(i) > pgpuPes.get(i).getPeProvisioner().getAvailableMips()) {
return false;
}
}
return true;
}
});
// if there is no candidate,
if (candidates.isEmpty()) {
return false;
}
return true;
}
@SuppressWarnings("unchecked")
@Override
public boolean allocatePgpuForVgpu(final Vgpu vgpu, final List<Double> mipsShare, final int gddramShare,
......@@ -142,58 +218,4 @@ public class VgpuSchedulerSpaceShared extends VgpuScheduler {
vgpu.setCurrentAllocatedMips(null);
}
@SuppressWarnings("unchecked")
@Override
public boolean isSuitable(final Vgpu vgpu) {
if (!isVideoCardSuitableForVgpu(vgpu)) {
return false;
}
final List<Double> mipsShare = vgpu.getCurrentRequestedMips();
final int gddramShare = vgpu.getCurrentRequestedGddram();
final long bwShare = vgpu.getCurrentRequestedBw();
List<Pgpu> candidates = (List<Pgpu>) CollectionUtils.select(getPgpuList(), new Predicate() {
@Override
public boolean evaluate(Object arg) {
Pgpu pgpu = (Pgpu) arg;
if (!pgpu.getGddramProvisioner().isSuitableForVgpu(vgpu, gddramShare)
|| !pgpu.getBwProvisioner().isSuitableForVgpu(vgpu, bwShare)) {
return false;
}
List<Pe> pgpuPes = pgpu.getPeList();
int freePes = CollectionUtils.countMatches(pgpuPes, new Predicate() {
@Override
public boolean evaluate(Object arg) {
Pe pe = (Pe) arg;
if (pe.getPeProvisioner().getTotalAllocatedMips() == 0) {
return true;
}
return false;
}
});
if (freePes < mipsShare.size()) {
return false;
}
// PEs in the pgpu are sorted according to their
// available mips
Collections.sort(pgpuPes, Collections.reverseOrder(new Comparator<Pe>() {
public int compare(Pe pe1, Pe pe2) {
return Double.compare(pe1.getPeProvisioner().getAvailableMips(),
pe2.getPeProvisioner().getAvailableMips());
}
}));
for (int i = 0; i < mipsShare.size(); i++) {
if (mipsShare.get(i) > pgpuPes.get(i).getPeProvisioner().getAvailableMips()) {
return false;
}
}
return true;
}
});
// if there is no candidate,
if (candidates.isEmpty()) {
return false;
}
return true;
}
}
......@@ -4,11 +4,13 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map.Entry;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.Predicate;
import org.cloudbus.cloudsim.Pe;
import org.cloudbus.cloudsim.gpu.selection.PgpuSelectionPolicy;
import org.cloudbus.cloudsim.gpu.util.GridVgpuUtil;
/**
* VgpuSchedulerTimeShared is a vgpu allocation policy that allocates one or
......@@ -30,6 +32,72 @@ public class VgpuSchedulerTimeShared extends VgpuScheduler {
super(videoCardType, pgpuList, pgpuSelectionPolicy);
}
/**
* Checks whether the vgpu type is supported by this video card type or not.
*
* @param vgpu
* the vgpu
* @return $true if the video card supports the vgpu type.
*/
protected boolean isVideoCardSuitableForVgpu(Vgpu vgpu) {
if (!GridVgpuUtil.isVideoCardSuitable(getVideoCardType(), vgpu.getType())) {
return false;
}
for (Entry<Pgpu, List<Vgpu>> entry : getPgpuVgpuMap().entrySet()) {
if (GridVgpuUtil.isPgpuSuitable(entry, vgpu)) {
return true;
}
}
return false;
}
@Override
public boolean isSuitable(final Vgpu vgpu) {
if (!isVideoCardSuitableForVgpu(vgpu)) {
return false;
}
final List<Double> mipsShare = vgpu.getCurrentRequestedMips();
final int gddramShare = vgpu.getCurrentRequestedGddram();
final long bwShare = vgpu.getCurrentRequestedBw();
@SuppressWarnings("unchecked")
List<Pgpu> candidates = (List<Pgpu>) CollectionUtils.select(getPgpuList(), new Predicate() {
@Override
public boolean evaluate(Object arg) {
Pgpu pgpu = (Pgpu) arg;
if (!pgpu.getGddramProvisioner().isSuitableForVgpu(vgpu, gddramShare)
|| !pgpu.getBwProvisioner().isSuitableForVgpu(vgpu, bwShare)) {
return false;
}
if (pgpu.getPeList().size() < mipsShare.size()) {
return false;
}
List<Pe> pgpuPes = pgpu.getPeList();
// PEs in the pgpu are sorted according to their
// available mips
Collections.sort(pgpuPes, Collections.reverseOrder(new Comparator<Pe>() {
public int compare(Pe pe1, Pe pe2) {
return Double.compare(pe1.getPeProvisioner().getAvailableMips(),
pe2.getPeProvisioner().getAvailableMips());
}
}));
for (int i = 0; i < mipsShare.size(); i++) {
if (mipsShare.get(i) > pgpuPes.get(i).getPeProvisioner().getAvailableMips()) {
return false;
}
}
return true;
}
});
// No two Vgpu PEs are mapped to one Pgpu PE, hence there must
// exists one such possible mapping at least
// if no suitable pgpu found, exit
if (candidates.isEmpty()) {
return false;
}
return true;
}
@Override
public boolean allocatePgpuForVgpu(final Vgpu vgpu, final List<Double> mipsShare, final int gddramShare,
final long bwShare) {
......@@ -115,51 +183,4 @@ public class VgpuSchedulerTimeShared extends VgpuScheduler {
vgpu.setCurrentAllocatedMips(null);
}
@Override
public boolean isSuitable(final Vgpu vgpu) {
if (!isVideoCardSuitableForVgpu(vgpu)) {
return false;
}
final List<Double> mipsShare = vgpu.getCurrentRequestedMips();
final int gddramShare = vgpu.getCurrentRequestedGddram();
final long bwShare = vgpu.getCurrentRequestedBw();
@SuppressWarnings("unchecked")
List<Pgpu> candidates = (List<Pgpu>) CollectionUtils.select(getPgpuList(), new Predicate() {
@Override
public boolean evaluate(Object arg) {
Pgpu pgpu = (Pgpu) arg;
if (!pgpu.getGddramProvisioner().isSuitableForVgpu(vgpu, gddramShare)
|| !pgpu.getBwProvisioner().isSuitableForVgpu(vgpu, bwShare)) {
return false;
}
if (pgpu.getPeList().size() < mipsShare.size()) {
return false;
}
List<Pe> pgpuPes = pgpu.getPeList();
// PEs in the pgpu are sorted according to their
// available mips
Collections.sort(pgpuPes, Collections.reverseOrder(new Comparator<Pe>() {
public int compare(Pe pe1, Pe pe2) {
return Double.compare(pe1.getPeProvisioner().getAvailableMips(),
pe2.getPeProvisioner().getAvailableMips());
}
}));
for (int i = 0; i < mipsShare.size(); i++) {
if (mipsShare.get(i) > pgpuPes.get(i).getPeProvisioner().getAvailableMips()) {
return false;
}
}
return true;
}
});
// No two Vgpu PEs are mapped to one Pgpu PE, hence there must
// exists one such possible mapping at least
// if no suitable pgpu found, exit
if (candidates.isEmpty()) {
return false;
}
return true;
}
}
......@@ -8,7 +8,7 @@ import java.util.List;
import org.cloudbus.cloudsim.gpu.Vgpu;
import org.cloudbus.cloudsim.gpu.VgpuScheduler;
import org.cloudbus.cloudsim.gpu.util.VgpuUtil;
import org.cloudbus.cloudsim.gpu.util.GridVgpuUtil;
/**
* {@link PerformanceModelGpuConstant} imposes a constant performance
......@@ -45,7 +45,7 @@ public class PerformanceModelGpuConstant implements PerformanceModel<VgpuSchedul
@Override
public List<Double> getAvailableMips(VgpuScheduler scheduler, Vgpu vgpu, List<Vgpu> vgpus) {
List<Double> allocatedMips = scheduler.getAllocatedMipsForVgpu(vgpu);
if (VgpuUtil.isPassThrough(vgpu)) {
if (GridVgpuUtil.isPassThrough(vgpu)) {
return allocatedMips;
}
List<Double> availableMips = new ArrayList<Double>(allocatedMips.size());
......
......@@ -6,16 +6,16 @@ import java.util.Map.Entry;
import org.apache.commons.lang3.ArrayUtils;
import org.cloudbus.cloudsim.gpu.Pgpu;
import org.cloudbus.cloudsim.gpu.Vgpu;
import org.cloudbus.cloudsim.gpu.VgpuTags;
import org.cloudbus.cloudsim.gpu.GridVgpuTags;
import org.cloudbus.cloudsim.gpu.VideoCardTags;
/**
* A class containing multiple convenient functions to work with Vgpus.
* A class containing multiple convenient functions to work with GRID Vgpus.
*
* @author Ahmad Siavashi
*
*/
public class VgpuUtil {
public class GridVgpuUtil {
/**
* Checks whether a videoCard type supports a given vgpu type or not.
......@@ -30,9 +30,9 @@ public class VgpuUtil {
public static boolean isVideoCardSuitable(int videoCardType, int vgpuType) {
switch (videoCardType) {
case VideoCardTags.NVIDIA_K1_CARD:
return ArrayUtils.contains(VgpuTags.K1_VGPUS, vgpuType);
return ArrayUtils.contains(GridVgpuTags.K1_VGPUS, vgpuType);
case VideoCardTags.NVIDIA_K2_CARD:
return ArrayUtils.contains(VgpuTags.K2_VGPUS, vgpuType);
return ArrayUtils.contains(GridVgpuTags.K2_VGPUS, vgpuType);
default:
return true;
}
......@@ -58,22 +58,22 @@ public class VgpuUtil {
}
int currentNumberOfVgpus = vgpus.size();
switch (newVgpu.getType()) {
case VgpuTags.K1_K120Q:
return currentNumberOfVgpus < VgpuTags.MAX_K120Q_VGPUS_PER_K1_PGPU;
case VgpuTags.K1_K140Q:
return currentNumberOfVgpus < VgpuTags.MAX_K140Q_VGPUS_PER_K1_PGPU;
case VgpuTags.K1_K160Q:
return currentNumberOfVgpus < VgpuTags.MAX_K160Q_VGPUS_PER_K1_PGPU;
case VgpuTags.K1_K180Q:
return currentNumberOfVgpus < VgpuTags.MAX_K180Q_VGPUS_PER_K1_PGPU;
case VgpuTags.K2_K220Q:
return currentNumberOfVgpus < VgpuTags.MAX_K220Q_VGPUS_PER_K2_PGPU;
case VgpuTags.K2_K240Q:
return currentNumberOfVgpus < VgpuTags.MAX_K240Q_VGPUS_PER_K2_PGPU;
case VgpuTags.K2_K260Q:
return currentNumberOfVgpus < VgpuTags.MAX_K260Q_VGPUS_PER_K2_PGPU;
case VgpuTags.K2_K280Q:
return currentNumberOfVgpus < VgpuTags.MAX_K280Q_VGPUS_PER_K2_PGPU;
case GridVgpuTags.K1_K120Q:
return currentNumberOfVgpus < GridVgpuTags.MAX_K120Q_VGPUS_PER_K1_PGPU;
case GridVgpuTags.K1_K140Q:
return currentNumberOfVgpus < GridVgpuTags.MAX_K140Q_VGPUS_PER_K1_PGPU;
case GridVgpuTags.K1_K160Q:
return currentNumberOfVgpus < GridVgpuTags.MAX_K160Q_VGPUS_PER_K1_PGPU;
case GridVgpuTags.K1_K180Q:
return currentNumberOfVgpus < GridVgpuTags.MAX_K180Q_VGPUS_PER_K1_PGPU;
case GridVgpuTags.K2_K220Q:
return currentNumberOfVgpus < GridVgpuTags.MAX_K220Q_VGPUS_PER_K2_PGPU;
case GridVgpuTags.K2_K240Q:
return currentNumberOfVgpus < GridVgpuTags.MAX_K240Q_VGPUS_PER_K2_PGPU;
case GridVgpuTags.K2_K260Q:
return currentNumberOfVgpus < GridVgpuTags.MAX_K260Q_VGPUS_PER_K2_PGPU;
case GridVgpuTags.K2_K280Q:
return currentNumberOfVgpus < GridVgpuTags.MAX_K280Q_VGPUS_PER_K2_PGPU;
}
if (pgpu.getGddramProvisioner().isSuitableForVgpu(newVgpu, newVgpu.getGddram())
&& pgpu.getBwProvisioner().isSuitableForVgpu(newVgpu, newVgpu.getBw())) {
......@@ -90,13 +90,13 @@ public class VgpuUtil {
* @return $true if the vgpu type is a pass-through type; $false otherwise.
*/
public static boolean isPassThrough(Vgpu vgpu) {
return ArrayUtils.contains(VgpuTags.PASS_THROUGH_VGPUS, vgpu.getType());
return ArrayUtils.contains(GridVgpuTags.PASS_THROUGH_VGPUS, vgpu.getType());
}
/**
* Cannot be instantiated (Singleton).
*/
private VgpuUtil() {
private GridVgpuUtil() {
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment