Commit 59a0ddda authored by Ahmad Siavashi's avatar Ahmad Siavashi

untested working example added

parent 3a7beb19
......@@ -250,7 +250,7 @@ public class Vgpu {
* @param mips
* the new mips
*/
protected void setPeMips(double mips) {
public void setPeMips(double mips) {
this.peMips = mips;
}
......@@ -269,7 +269,7 @@ public class Vgpu {
* @param numberOfPes
* the new number of pes
*/
protected void setNumberOfPes(int numberOfPes) {
public void setNumberOfPes(int numberOfPes) {
this.numberOfPes = numberOfPes;
}
......@@ -315,7 +315,7 @@ public class Vgpu {
* @pre bw > 0
* @post $none
*/
protected void setBw(long bw) {
public void setBw(long bw) {
this.bw = bw;
}
......@@ -336,7 +336,7 @@ public class Vgpu {
* @param type
* the new virtual gpu type
*/
protected void setType(int type) {
public void setType(int type) {
this.type = type;
}
......
......@@ -21,8 +21,6 @@ import org.cloudbus.cloudsim.gpu.util.GridVgpuUtil;
*/
public class PerformanceModelGpuConstant implements PerformanceModel<VgpuScheduler, Vgpu> {
public static final double TOTAL_CAPACITY = 0;
protected final double gain;
/**
......
/**
*
*/
package org.cloudbus.cloudsim.gpu.remote;
import java.util.ArrayList;
import java.util.List;
import org.cloudbus.cloudsim.Log;
import org.cloudbus.cloudsim.Pe;
import org.cloudbus.cloudsim.Vm;
import org.cloudbus.cloudsim.VmScheduler;
import org.cloudbus.cloudsim.gpu.GpuVm;
import org.cloudbus.cloudsim.gpu.Vgpu;
import org.cloudbus.cloudsim.gpu.allocation.VideoCardAllocationPolicy;
import org.cloudbus.cloudsim.gpu.performance.PerformanceScheduler;
import org.cloudbus.cloudsim.gpu.power.PowerGpuHost;
import org.cloudbus.cloudsim.power.models.PowerModel;
import org.cloudbus.cloudsim.provisioners.BwProvisioner;
import org.cloudbus.cloudsim.provisioners.RamProvisioner;
/**
*
* A {@link PowerGpuHost} which supports GPU remoting.
*
* @author Ahmad Siavashi
*
*/
public class RemoteGpuHost extends PowerGpuHost {
/**
* A {@link PowerGpuHost} which supports GPU remoting.
*/
public RemoteGpuHost(int id, int type, RamProvisioner ramProvisioner, BwProvisioner bwProvisioner, long storage,
List<? extends Pe> peList, VmScheduler vmScheduler, VideoCardAllocationPolicy videoCardAllocationPolicy,
PowerModel powerModel) {
super(id, type, ramProvisioner, bwProvisioner, storage, peList, vmScheduler, videoCardAllocationPolicy,
powerModel);
}
/**
* A {@link PowerGpuHost} which supports GPU remoting.
*/
public RemoteGpuHost(int id, int type, RamProvisioner ramProvisioner, BwProvisioner bwProvisioner, long storage,
List<? extends Pe> peList, VmScheduler vmScheduler, PowerModel powerModel) {
super(id, type, ramProvisioner, bwProvisioner, storage, peList, vmScheduler, powerModel);
// TODO Auto-generated constructor stub
}
@Override
public double updateVmsProcessing(double currentTime) {
// Update VMs progress
double smallerTime = Double.MAX_VALUE;
for (Vm vm : getVmList()) {
double time = vm.updateVmProcessing(currentTime, getVmScheduler().getAllocatedMipsForVm(vm));
if (time > 0.0 && time < smallerTime) {
smallerTime = time;
}
}
// Update resident vgpus progress, if any
if (getVideoCardAllocationPolicy() == null) {
return smallerTime;
} // else
// To collect Vm that are probably sharing a resource
List<Vgpu> runningVgpus = new ArrayList<Vgpu>();
// Collect running gpu vms
for (Vgpu vgpu : getVideoCardAllocationPolicy().getVgpuVideoCardMap().keySet()) {
if (vgpu.getGpuTaskScheduler().runningTasks() > 0) {
runningVgpus.add(vgpu);
}
}
for (Vgpu vgpu : getVideoCardAllocationPolicy().getVgpuVideoCardMap().keySet()) {
@SuppressWarnings("unchecked")
PerformanceScheduler<Vgpu> vgpuScheduler = (PerformanceScheduler<Vgpu>) getVideoCardAllocationPolicy()
.getVgpuVideoCardMap().get(vgpu).getVgpuScheduler();
double time = vgpu.updateTaskProcessing(currentTime, vgpuScheduler.getAvailableMips(vgpu, runningVgpus));
if (time > 0.0 && time < smallerTime) {
smallerTime = time;
}
}
return smallerTime;
}
@Override
public boolean isSuitableForVm(Vm vm) {
// Checking host resources
boolean hasStorage = getStorage() >= vm.getSize();
boolean hasRam = getRamProvisioner().isSuitableForVm(vm, vm.getCurrentRequestedRam());
boolean hasBw = getBwProvisioner().isSuitableForVm(vm, vm.getCurrentRequestedBw());
boolean hasMips = getVmScheduler().getPeCapacity() >= vm.getCurrentRequestedMaxMips()
&& getVmScheduler().getAvailableMips() >= vm.getCurrentRequestedTotalMips();
if (!hasStorage || !hasRam || !hasBw || !hasMips) {
return false;
}
// Checking GPU resources of the host
Vgpu vgpu = ((GpuVm) vm).getVgpu();
// if the VM has no vGPU -> return true.
if (vgpu == null) {
return true;
}
// if the VM has a remote vGPU
else if (!isVgpuLocal(vgpu)) {
return true;
}
// if the VM has a local vGPU and the host has no local video card -> return
// false.
else if (getVideoCardAllocationPolicy() == null) {
return false;
}
// if the VM has a local vGPU and the host has video card(s) -> check
// compatibility.
return getVideoCardAllocationPolicy().isSuitable(vgpu);
}
@Override
public boolean vmCreate(Vm vm) {
// Allocation of host resources
if (getStorage() < vm.getSize()) {
Log.printConcatLine("[VmScheduler.vmCreate] Allocation of VM #", vm.getId(), " to Host #", getId(),
" failed by storage");
return false;
}
if (!getRamProvisioner().allocateRamForVm(vm, vm.getCurrentRequestedRam())) {
Log.printConcatLine("[VmScheduler.vmCreate] Allocation of VM #", vm.getId(), " to Host #", getId(),
" failed by RAM");
return false;
}
if (!getBwProvisioner().allocateBwForVm(vm, vm.getCurrentRequestedBw())) {
Log.printConcatLine("[VmScheduler.vmCreate] Allocation of VM #", vm.getId(), " to Host #", getId(),
" failed by BW");
getRamProvisioner().deallocateRamForVm(vm);
return false;
}
if (!getVmScheduler().allocatePesForVm(vm, vm.getCurrentRequestedMips())) {
Log.printConcatLine("[VmScheduler.vmCreate] Allocation of VM #", vm.getId(), " to Host #", getId(),
" failed by MIPS");
getRamProvisioner().deallocateRamForVm(vm);
getBwProvisioner().deallocateBwForVm(vm);
return false;
}
setStorage(getStorage() - vm.getSize());
// Device (GPU) allocation
Vgpu vgpu = ((GpuVm) vm).getVgpu();
// if the VM has no vGPU or if the VM has a remote vGPU -> success.
if (vgpu == null || !isVgpuLocal(vgpu)) {
getVmList().add(vm);
vm.setHost(this);
return true;
}
// if the VM has a local vGPU but the host has no local video card -> fail.
else if (getVideoCardAllocationPolicy() == null) {
rollbackHostResourceAllocation(vm);
return false;
}
// if the VM has a local vGPU and the host has local video card(s) -> check
boolean isVgpuAllocated = getVideoCardAllocationPolicy().allocate(vgpu, vgpu.getPCIeBw());
// if vGPU allocation failed -> fail.
if (!isVgpuAllocated) {
Log.printConcatLine("[VmScheduler.vmCreate] Allocation of GPU accelerated VM #", vm.getId(), " to Host #",
getId(), " failed due to vgpu allocation failure.");
rollbackHostResourceAllocation(vm);
return false;
} // else -> success
getVmList().add(vm);
vm.setHost(this);
return true;
}
@Override
protected void vmDeallocate(Vm vm) {
// vm removal
getVmList().remove(vm);
// Vm deallocation */
rollbackHostResourceAllocation(vm);
// get vgpu
Vgpu vgpu = ((GpuVm) vm).getVgpu();
// if the VM has no vGPU -> done
if (vgpu == null) {
return;
} else if (isVgpuLocal(vgpu) && getVideoCardAllocationPolicy() != null) {
// Vgpu deallocation
getVideoCardAllocationPolicy().deallocate(vgpu);
}
}
protected boolean isVgpuLocal(Vgpu vgpu) {
if (vgpu.getType() == RemoteVgpuTags.LOCAL_EXCLUSIVE || vgpu.getType() == RemoteVgpuTags.LOCAL_SHARED) {
return true;
}
return false;
}
}
package org.cloudbus.cloudsim.gpu.remote;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.cloudbus.cloudsim.Host;
import org.cloudbus.cloudsim.Log;
import org.cloudbus.cloudsim.Vm;
import org.cloudbus.cloudsim.core.CloudSim;
import org.cloudbus.cloudsim.gpu.GpuVm;
import org.cloudbus.cloudsim.gpu.GpuVmAllocationPolicySimple;
import org.cloudbus.cloudsim.gpu.Vgpu;
import org.cloudbus.cloudsim.gpu.power.PowerGpuHost;
/**
* This class extends {@link GpuVmAllocationPolicySimple} to add support for GPU
* remoting.
*
* @author Ahmad Siavashi
*
*/
public class RemoteGpuVmAllocationPolicyFirstFit extends GpuVmAllocationPolicySimple {
private List<PowerGpuHost> gpuHosts;
private Map<Vgpu, RemoteGpuHost> remoteVgpuHosts;
/**
* This class extends {@link GpuVmAllocationPolicySimple} to add support for GPU
* remoting.
*
* @see {@link GpuVmAllocationPolicySimple}
*/
public RemoteGpuVmAllocationPolicyFirstFit(List<? extends Host> list) {
super(list);
setRemoteVgpuHosts(new HashMap<>());
setGpuHosts(new ArrayList<>());
updateGpuHosts(getHostList());
}
@Override
public boolean allocateHostForVm(Vm vm, Host host) {
if (!getVmTable().containsKey(vm.getUid())) {
Vgpu vgpu = ((GpuVm) vm).getVgpu();
boolean result = host.vmCreate(vm);
if (!result) {
return false;
}
// if Vm has no Vgpu or has a local Vgpu which is allocated in vmCreate
else if (vgpu == null || !isVgpuRemote(vgpu)) {
getVmTable().put(vm.getUid(), host);
Log.formatLine("%.2f: VM #" + vm.getId() + " has been allocated to the host #" + host.getId(),
CloudSim.clock());
Log.printLine("{'clock': " + CloudSim.clock() + ", 'event': 'vm allocation', 'vm': " + vm.getId()
+ ", 'host': " + host.getId() + "}");
return true;
}
// if Vm has a remote Vgpu
for (PowerGpuHost gpuHost : getGpuHosts()) {
boolean isVgpuAllocated = gpuHost.getVideoCardAllocationPolicy().allocate(vgpu, vgpu.getPCIeBw());
if (isVgpuAllocated) {
getVmTable().put(vm.getUid(), host);
Log.formatLine("%.2f: VM #" + vm.getId() + " has been allocated to the host #" + host.getId(),
CloudSim.clock());
Log.printLine("{'clock': " + CloudSim.clock() + ", 'event': 'vm allocation', 'vm': " + vm.getId()
+ ", 'host': " + host.getId() + "}");
return true;
}
}
// failed to find a remote GPU -> free allocated resources
host.vmDestroy(vm);
}
return false;
}
protected boolean isVgpuRemote(Vgpu vgpu) {
if (vgpu.getType() == RemoteVgpuTags.REMOTE_EXCLUSIVE || vgpu.getType() == RemoteVgpuTags.REMOTE_SHARED) {
return true;
}
return false;
}
// Add GPU-equipped hosts
protected void updateGpuHosts(List<PowerGpuHost> hosts) {
getGpuHosts().clear();
for (PowerGpuHost host : hosts) {
if (host.getVideoCardAllocationPolicy() != null) {
getGpuHosts().add(host);
}
}
}
public List<PowerGpuHost> getGpuHosts() {
return gpuHosts;
}
protected void setGpuHosts(List<PowerGpuHost> gpuHosts) {
this.gpuHosts = gpuHosts;
}
public Map<Vgpu, RemoteGpuHost> getRemoteVgpuHosts() {
return remoteVgpuHosts;
}
protected void setRemoteVgpuHosts(Map<Vgpu, RemoteGpuHost> remoteVgpuHosts) {
this.remoteVgpuHosts = remoteVgpuHosts;
}
}
package org.cloudbus.cloudsim.gpu.remote;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.Predicate;
import org.apache.commons.lang3.NotImplementedException;
import org.cloudbus.cloudsim.Pe;
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.performance.PerformanceVgpuSchedulerFairShare;
import org.cloudbus.cloudsim.gpu.performance.models.PerformanceModel;
import org.cloudbus.cloudsim.gpu.selection.PgpuSelectionPolicy;
import org.cloudbus.cloudsim.util.MathUtil;
/**
* Extends {@link VgpuSchedulerFairShare} to add support for GPU remoting.
*
* @author Ahmad Siavashi
*/
public class RemoteVgpuSchedulerFairShare extends PerformanceVgpuSchedulerFairShare {
/**
* Extends {@link VgpuSchedulerFairShare} to add support for GPU remoting.
*
* @see {@link VgpuSchedulerFairShare}
*/
public RemoteVgpuSchedulerFairShare(int videoCardType, List<Pgpu> pgpuList, PgpuSelectionPolicy pgpuSelectionPolicy,
PerformanceModel<VgpuScheduler, Vgpu> performanceModel) {
super(videoCardType, pgpuList, pgpuSelectionPolicy, performanceModel);
}
@Override
protected boolean isVideoCardSuitableForVgpu(Vgpu vgpu) {
throw new NotImplementedException("This method is not implemented.");
}
@SuppressWarnings("unchecked")
@Override
public boolean isSuitable(final Vgpu vgpu) {
final int gddramShare = vgpu.getCurrentRequestedGddram();
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)) {
return false;
}
if (isVgpuExclusive(vgpu) && getPgpuVgpuMap().get(pgpu).size() > 0) {
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,
final long bwShare) {
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)) {
return false;
}
if (isVgpuExclusive(vgpu) && getPgpuVgpuMap().get(pgpu).size() > 0) {
return false;
}
return true;
}
});
Pgpu selectedPgpu = getPgpuSelectionPolicy().selectPgpu(this, candidates);
if (selectedPgpu == null) {
return false;
}
// set processing power according to the allocated pgpu
vgpu.setNumberOfPes(selectedPgpu.getPeList().size());
vgpu.setPeMips(selectedPgpu.getPeList().get(0).getMips());
final List<Double> VgpuMipsShare = vgpu.getCurrentRequestedMips();
final long vgpuBwShare = selectedPgpu.getBwProvisioner().getBw();
selectedPgpu.getGddramProvisioner().allocateGddramForVgpu(vgpu, gddramShare);
// memory BW is assumed/supposed to be ignored
selectedPgpu.getBwProvisioner().allocateBwForVgpu(vgpu, vgpuBwShare);
getPgpuVgpuMap().get(selectedPgpu).add(vgpu);
getRequestedMipsMap().put(vgpu, VgpuMipsShare);
getVgpuPeMap().put(vgpu, new ArrayList<Pe>());
double mipsChange = MathUtil.sum(VgpuMipsShare);
redistributeMipsDueToOverSubscription(selectedPgpu, mipsChange);
return true;
}
protected boolean isVgpuExclusive(Vgpu vgpu) {
int type = vgpu.getType();
if (type == RemoteVgpuTags.LOCAL_EXCLUSIVE || type == RemoteVgpuTags.REMOTE_EXCLUSIVE) {
return true;
}
return false;
}
}
package org.cloudbus.cloudsim.gpu.remote;
/**
*
* The modes supported in remote GPU virtualization.
*
* @author Ahmad Siavashi
*
*/
public class RemoteVgpuTags {
public static final int REMOTE_EXCLUSIVE = 0;
public static final int REMOTE_SHARED = 1;
public static final int LOCAL_EXCLUSIVE = 2;
public static final int LOCAL_SHARED = 3;
}
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