Commit 23c761c7 authored by Ahmad Siavashi's avatar Ahmad Siavashi

Add gpu package to cloudsim-4.0

parent 2d8f1c61
# CloudSim: A Framework For Modeling And Simulation Of Cloud Computing Infrastructures And Services #
## GPUCloudSim: an extension of CloudSim for modeling and simulation of GPUs in cloud data centers
Cloud computing is the leading approach for delivering reliable, secure, fault-tolerant, sustainable, and scalable computational services. Hence timely, repeatable, and controllable methodologies for performance evaluation of new cloud applications and policies before their actual development are reqruied. Because utilization of real testbeds limits the experiments to the scale of the testbed and makes the reproduction of results an extremely difficult undertaking, simulation may be used.
In order to satisfy graphical and computational requirements of end-users, today cloud providers offer GPU-enabled services. To ease-up conducting experimental studies on GPU-enabled cloud computing environments, we provide an extension to [CloudSim](http://cloudbus.org/cloudsim/) simulator. Our extension includes models and provisioning and scheduling policies to enable the modeling and simulation of GPUs in data centers.
CloudSim goal is to provide a generalized and extensible simulation framework that enables modeling, simulation, and experimentation of emerging Cloud computing infrastructures and application services, allowing its users to focus on specific system design issues that they want to investigate, without getting concerned about the low level details related to Cloud-based infrastructures and services.
-----------------------------------------
If you used the extension, please consider citing the following paper,
> Siavashi, A., Momtazpour, M. GPUCloudSim: an extension of CloudSim for modeling and simulation of GPUs in cloud data centers. J Supercomput 75, 2535–2561 (2019).
-----------------------------------------
CloudSim is developed in [the Cloud Computing and Distributed Systems (CLOUDS) Laboratory](http://cloudbus.org/), at [the Computer Science and Software Engineering Department](http://www.csse.unimelb.edu.au/) of [the University of Melbourne](http://www.unimelb.edu.au/).
We are constantly adding new features to the extension. Please consider reporting any issue you find helpful to improve the quality of the work.
More information can be found on the [CloudSim's web site](http://cloudbus.org/cloudsim/).
### Main features
* Support for modeling and simulation of large scale GPU-enabled cloud platforms
* Support for modeling and simulation of energy-aware GPU-equipped data centers
* Support for modeling and simulation of multi-video card servers
* Support for modeling and simulation of multi-GPU video cards
* Support for modeling and simulation of GPU-enabled VMs
* Support for simulation of mixed workload and heterogeneous infrastructure
* Support for user-defined GPU scheduling policies
* Support for user-defined GPU provisioning policies
* Support for modeling and simulation of GPU applications
* Support for user-defined GPU application scheduling policies
* Support for modeling and simulation of GPU remoting virtualization technology ([Siavashi et al. 2022](https://papers.ssrn.com/sol3/papers.cfm?abstract_id=4030263))
* Support for modeling and simulation of NVIDIA GRID GPU virtualization technology
* Support for modeling and simulation of full and para GPU virtualization technologies
* Support for modeling and simulation of virtualization-incurred performance overhead
* Support for modeling and simulation of interference among co-running GPU applications
# Main features #
### Download
* support for modeling and simulation of large scale Cloud computing data centers
* support for modeling and simulation of virtualized server hosts, with customizable policies for provisioning host resources to virtual machines
* support for modeling and simulation of application containers
* support for modeling and simulation of energy-aware computational resources
* support for modeling and simulation of data center network topologies and message-passing applications
* support for modeling and simulation of federated clouds
* support for dynamic insertion of simulation elements, stop and resume of simulation
* support for user-defined policies for allocation of hosts to virtual machines and policies for allocation of host resources to virtual machines
This package contains CloudSim 4.0 with the latest version of the GPU extension.
### Disclaimer
# Download #
The downloaded package contains all the source code, examples, jars, and API html files.
# Publications #
* Anton Beloglazov, and Rajkumar Buyya, [Optimal Online Deterministic Algorithms and Adaptive Heuristics for Energy and Performance Efficient Dynamic Consolidation of Virtual Machines in Cloud Data Centers](http://beloglazov.info/papers/2012-optimal-algorithms-ccpe.pdf), Concurrency and Computation: Practice and Experience, Volume 24, Number 13, Pages: 1397-1420, John Wiley & Sons, Ltd, New York, USA, 2012.
* Saurabh Kumar Garg and Rajkumar Buyya, [NetworkCloudSim: Modelling Parallel Applications in Cloud Simulations](http://www.cloudbus.org/papers/NetworkCloudSim2011.pdf), Proceedings of the 4th IEEE/ACM International Conference on Utility and Cloud Computing (UCC 2011, IEEE CS Press, USA), Melbourne, Australia, December 5-7, 2011.
* **Rodrigo N. Calheiros, Rajiv Ranjan, Anton Beloglazov, Cesar A. F. De Rose, and Rajkumar Buyya, [CloudSim: A Toolkit for Modeling and Simulation of Cloud Computing Environments and Evaluation of Resource Provisioning Algorithms](http://www.buyya.com/papers/CloudSim2010.pdf), Software: Practice and Experience (SPE), Volume 41, Number 1, Pages: 23-50, ISSN: 0038-0644, Wiley Press, New York, USA, January, 2011. (Preferred reference for CloudSim)**
* Bhathiya Wickremasinghe, Rodrigo N. Calheiros, Rajkumar Buyya, [CloudAnalyst: A CloudSim-based Visual Modeller for Analysing Cloud Computing Environments and Applications](http://www.cloudbus.org/papers/CloudAnalyst-AINA2010.pdf), Proceedings of the 24th International Conference on Advanced Information Networking and Applications (AINA 2010), Perth, Australia, April 20-23, 2010.
* Rajkumar Buyya, Rajiv Ranjan and Rodrigo N. Calheiros, [Modeling and Simulation of Scalable Cloud Computing Environments and the CloudSim Toolkit: Challenges and Opportunities](http://www.cloudbus.org/papers/CloudSim-HPCS2009.pdf), Proceedings of the 7th High Performance Computing and Simulation Conference (HPCS 2009, ISBN: 978-1-4244-4907-1, IEEE Press, New York, USA), Leipzig, Germany, June 21-24, 2009.
[![](http://www.cloudbus.org/logo/cloudbuslogo-v5a.png)](http://cloudbus.org/)
This code is provided as is, and no guarantee is given that this code will preform in the desired way.
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>cloudsim-examples</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding/<project>=UTF-8
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
......@@ -16,6 +16,11 @@
<artifactId>cloudsim</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>de.vandermeer</groupId>
<artifactId>asciitable</artifactId>
<version>0.3.2</version>
</dependency>
</dependencies>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>cloudsim</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/test/java=UTF-8
encoding//src/test/resources=UTF-8
encoding/<project>=UTF-8
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
......@@ -67,6 +67,11 @@
</plugins>
</build>
<dependencies>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-math3</artifactId>
......
package org.cloudbus.cloudsim.gpu;
/**
*
* Contains constants related to the way {@link VideoCard}s are connected to
* {@link GpuHost}s.
*
* @author Ahmad Siavashi
*
*/
public class BusTags {
/** 15.75 GB/s */
public final static int PCI_E_3_X16_BW = 15750; // 15750 MB/s
}
package org.cloudbus.cloudsim.gpu;
import java.util.List;
import org.cloudbus.cloudsim.Cloudlet;
import org.cloudbus.cloudsim.UtilizationModel;
/**
* To represent an application with both host and device execution
* requirements, GpuCloudlet extends {@link Cloudlet} to include a
* {@link GpuTask}.
*
* @author Ahmad Siavashi
*
*/
public class GpuCloudlet extends Cloudlet {
/**
* A tag associated with the GpuCloudlet. A tag can be used to describe the
* application.
*/
private String tag;
/**
* The GPU part of the application.
*/
private GpuTask gpuTask;
/**
* Create a GpuCloudlet. {@link Cloudlet} represents the host portion of the
* application while {@link GpuTask} represents the device portion.
*
* @param gpuCloudletId gpuCloudlet id
* @param cloudletLength length of the host portion
* @param pesNumber number of threads
* @param cloudletFileSize size of the application
* @param cloudletOutputSize size of the application when executed
* @param utilizationModelCpu CPU utilization model of host portion
* @param utilizationModelRam RAM utilization model of host portion
* @param utilizationModelBw BW utilization model of host portion
* @param gpuTask the device portion of the application
*/
public GpuCloudlet(int gpuCloudletId, long cloudletLength, int pesNumber, long cloudletFileSize,
long cloudletOutputSize, UtilizationModel utilizationModelCpu, UtilizationModel utilizationModelRam,
UtilizationModel utilizationModelBw, GpuTask gpuTask) {
super(gpuCloudletId, cloudletLength, pesNumber, cloudletFileSize, cloudletOutputSize, utilizationModelCpu,
utilizationModelRam, utilizationModelBw);
setGpuTask(gpuTask);
}
/**
* Create a GpuCloudlet. {@link Cloudlet} represents the host portion of the
* application while {@link GpuTask} represents the device portion.
*
* @param gpuCloudletId gpuCloudlet id
* @param cloudletLength length of the host portion
* @param pesNumber number of threads
* @param cloudletFileSize size of the application
* @param cloudletOutputSize size of the application when executed
* @param utilizationModelCpu CPU utilization model of host portion
* @param utilizationModelRam RAM utilization model of host portion
* @param utilizationModelBw BW utilization model of host portion
* @param gpuTask the device portion of the application
* @param record
* @param fileList
*/
public GpuCloudlet(int cloudletId, long cloudletLength, int pesNumber, long cloudletFileSize,
long cloudletOutputSize, UtilizationModel utilizationModelCpu, UtilizationModel utilizationModelRam,
UtilizationModel utilizationModelBw, GpuTask gpuTask, boolean record, List<String> fileList) {
super(cloudletId, cloudletLength, pesNumber, cloudletFileSize, cloudletOutputSize, utilizationModelCpu,
utilizationModelRam, utilizationModelBw, record, fileList);
setGpuTask(gpuTask);
}
/**
* Create a GpuCloudlet. {@link Cloudlet} represents the host portion of the
* application while {@link GpuTask} represents the device portion.
*
* @param gpuCloudletId gpuCloudlet id
* @param cloudletLength length of the host portion
* @param pesNumber number of threads
* @param cloudletFileSize size of the application
* @param cloudletOutputSize size of the application when executed
* @param utilizationModelCpu CPU utilization model of host portion
* @param utilizationModelRam RAM utilization model of host portion
* @param utilizationModelBw BW utilization model of host portion
* @param gpuTask the device portion of the application
* @param fileList
*/
public GpuCloudlet(int cloudletId, long cloudletLength, int pesNumber, long cloudletFileSize,
long cloudletOutputSize, UtilizationModel utilizationModelCpu, UtilizationModel utilizationModelRam,
UtilizationModel utilizationModelBw, GpuTask gpuTask, List<String> fileList) {
super(cloudletId, cloudletLength, pesNumber, cloudletFileSize, cloudletOutputSize, utilizationModelCpu,
utilizationModelRam, utilizationModelBw, fileList);
setGpuTask(gpuTask);
}
/**
* Create a GpuCloudlet. {@link Cloudlet} represents the host portion of the
* application while {@link GpuTask} represents the device portion.
*
* @param gpuCloudletId gpuCloudlet id
* @param cloudletLength length of the host portion
* @param pesNumber number of threads
* @param cloudletFileSize size of the application
* @param cloudletOutputSize size of the application when executed
* @param utilizationModelCpu CPU utilization model of host portion
* @param utilizationModelRam RAM utilization model of host portion
* @param utilizationModelBw BW utilization model of host portion
* @param gpuTask the device portion of the application
* @param record
*/
public GpuCloudlet(int cloudletId, long cloudletLength, int pesNumber, long cloudletFileSize,
long cloudletOutputSize, UtilizationModel utilizationModelCpu, UtilizationModel utilizationModelRam,
UtilizationModel utilizationModelBw, GpuTask gpuTask, boolean record) {
super(cloudletId, cloudletLength, pesNumber, cloudletFileSize, cloudletOutputSize, utilizationModelCpu,
utilizationModelRam, utilizationModelBw, record);
setGpuTask(gpuTask);
}
/**
* Create a GpuCloudlet. {@link Cloudlet} represents the host portion of the
* application.
*
* @param gpuCloudletId gpuCloudlet id
* @param cloudletLength length of the host portion
* @param pesNumber number of threads
* @param cloudletFileSize size of the application
* @param cloudletOutputSize size of the application when executed
* @param utilizationModelCpu CPU utilization model of host portion
* @param utilizationModelRam RAM utilization model of host portion
* @param utilizationModelBw BW utilization model of host portion
* @param record
*/
public GpuCloudlet(int cloudletId, long cloudletLength, int pesNumber, long cloudletFileSize,
long cloudletOutputSize, UtilizationModel utilizationModelCpu, UtilizationModel utilizationModelRam,
UtilizationModel utilizationModelBw, boolean record) {
super(cloudletId, cloudletLength, pesNumber, cloudletFileSize, cloudletOutputSize, utilizationModelCpu,
utilizationModelRam, utilizationModelBw, record);
}
/**
* @return the device portion
*/
public GpuTask getGpuTask() {
return gpuTask;
}
/**
* @param gpuTask the device portion
*/
protected void setGpuTask(GpuTask gpuTask) {
this.gpuTask = gpuTask;
if (gpuTask != null && gpuTask.getCloudlet() == null) {
gpuTask.setCloudlet(this);
}
}
/**
* @return the tag
*/
public String getTag() {
return tag;
}
/**
* @param tag the tag to set
*/
public void setTag(String tag) {
this.tag = tag;
}
}
package org.cloudbus.cloudsim.gpu;
/**
*
* @author Ahmad Siavashi
*
*/
public interface GpuCloudletScheduler {
public boolean hasGpuTask();
public GpuTask getNextGpuTask();
public boolean notifyGpuTaskCompletion(GpuTask gt);
}
package org.cloudbus.cloudsim.gpu;
import java.util.ArrayList;
import java.util.List;
import org.cloudbus.cloudsim.Cloudlet;
import org.cloudbus.cloudsim.CloudletSchedulerSpaceShared;
import org.cloudbus.cloudsim.ResCloudlet;
import org.cloudbus.cloudsim.core.CloudSim;
/**
* {@link GpuCloudletSchedulerSpaceShared} extends
* {@link CloudletSchedulerSpaceShared} to schedule {@link GpuCloudlet}s.
*
* @author Ahmad Siavashi
*
*/
public class GpuCloudletSchedulerSpaceShared extends CloudletSchedulerSpaceShared implements GpuCloudletScheduler {
private List<GpuTask> gpuTaskList;
/**
* Space Shared scheduler for GpuCloudlets. Assumes all PEs have same MIPS
* capacity.
*/
public GpuCloudletSchedulerSpaceShared() {
super();
setGpuTaskList(new ArrayList<GpuTask>());
}
@Override
public double cloudletSubmit(Cloudlet cloudlet, double fileTransferTime) {
// it can go to the exec list
if ((currentCpus - usedPes) >= cloudlet.getNumberOfPes()) {
ResGpuCloudlet rgcl = new ResGpuCloudlet((GpuCloudlet) cloudlet);
rgcl.setCloudletStatus(Cloudlet.INEXEC);
for (int i = 0; i < cloudlet.getNumberOfPes(); i++) {
rgcl.setMachineAndPeId(0, i);
}
getCloudletExecList().add(rgcl);
usedPes += cloudlet.getNumberOfPes();
} else {// no enough free PEs: go to the waiting queue
ResGpuCloudlet rgcl = new ResGpuCloudlet((GpuCloudlet) cloudlet);
rgcl.setCloudletStatus(Cloudlet.QUEUED);
getCloudletWaitingList().add(rgcl);
return 0.0;
}
// calculate the expected time for cloudlet completion
double capacity = 0.0;
int cpus = 0;
for (Double mips : getCurrentMipsShare()) {
capacity += mips;
if (mips > 0) {
cpus++;
}
}
currentCpus = cpus;
capacity /= cpus;
// use the current capacity to estimate the extra amount of
// time to file transferring. It must be added to the cloudlet length
double extraSize = capacity * fileTransferTime;
long length = cloudlet.getCloudletLength();
length += extraSize;
cloudlet.setCloudletLength(length);
return cloudlet.getCloudletLength() / capacity;
}
@Override
public void cloudletFinish(ResCloudlet rcl) {
ResGpuCloudlet rgcl = (ResGpuCloudlet) rcl;
if (!rgcl.hasGpuTask()) {
super.cloudletFinish(rcl);
} else {
GpuTask gt = rgcl.getGpuTask();
getGpuTaskList().add(gt);
try {
rgcl.setCloudletStatus(GpuCloudlet.PAUSED);
getCloudletPausedList().add(rgcl);
} catch (Exception e) {
e.printStackTrace();
CloudSim.abruptallyTerminate();
}
usedPes -= rgcl.getNumberOfPes();
}
}
protected List<GpuTask> getGpuTaskList() {
return gpuTaskList;
}
protected void setGpuTaskList(List<GpuTask> gpuTaskList) {
this.gpuTaskList = gpuTaskList;
}
@Override
public boolean hasGpuTask() {
return !getGpuTaskList().isEmpty();
}
@Override
public GpuTask getNextGpuTask() {
if (hasGpuTask()) {
return getGpuTaskList().remove(0);
}
return null;
}
@Override
public boolean notifyGpuTaskCompletion(GpuTask gt) {
for (ResCloudlet rcl : getCloudletPausedList()) {
ResGpuCloudlet rgcl = (ResGpuCloudlet) rcl;
if (rgcl.getGpuTask() == gt) {
rgcl.setCloudletStatus(GpuCloudlet.SUCCESS);
rgcl.finalizeCloudlet();
return true;
}
}
return false;
}
}
package org.cloudbus.cloudsim.gpu;
import java.util.ArrayList;
import java.util.List;
import org.cloudbus.cloudsim.Cloudlet;
import org.cloudbus.cloudsim.CloudletSchedulerTimeShared;
import org.cloudbus.cloudsim.ResCloudlet;
import org.cloudbus.cloudsim.core.CloudSim;
/**
* {@link GpuCloudletSchedulerTimeShared} extends
* {@link CloudletSchedulerTimeShared} to schedule {@link GpuCloudlet}s.
*
* @author Ahmad Siavashi
*
*/
public class GpuCloudletSchedulerTimeShared extends CloudletSchedulerTimeShared implements GpuCloudletScheduler {
private List<GpuTask> gpuTaskList;
/**
* {@link CloudletSchedulerTimeShared} with GpuCloudlet support. Assumes all PEs have same MIPS
* capacity.
*/
public GpuCloudletSchedulerTimeShared() {
super();
setGpuTaskList(new ArrayList<GpuTask>());
}
@Override
public double cloudletSubmit(Cloudlet cloudlet, double fileTransferTime) {
ResGpuCloudlet rcl = new ResGpuCloudlet((GpuCloudlet) cloudlet);
rcl.setCloudletStatus(Cloudlet.INEXEC);
for (int i = 0; i < cloudlet.getNumberOfPes(); i++) {
rcl.setMachineAndPeId(0, i);
}
getCloudletExecList().add(rcl);
// use the current capacity to estimate the extra amount of
// time to file transferring. It must be added to the cloudlet length
double extraSize = getCapacity(getCurrentMipsShare()) * fileTransferTime;
long length = (long) (cloudlet.getCloudletLength() + extraSize);
cloudlet.setCloudletLength(length);
return cloudlet.getCloudletLength() / getCapacity(getCurrentMipsShare());
}
@Override
public void cloudletFinish(ResCloudlet rcl) {
ResGpuCloudlet rgcl = (ResGpuCloudlet) rcl;
if (!rgcl.hasGpuTask()) {
super.cloudletFinish(rcl);
} else {
GpuTask gt = rgcl.getGpuTask();
getGpuTaskList().add(gt);
try {
rgcl.setCloudletStatus(GpuCloudlet.PAUSED);
getCloudletPausedList().add(rgcl);
} catch (Exception e) {
e.printStackTrace();
CloudSim.abruptallyTerminate();
}
}
}
protected List<GpuTask> getGpuTaskList() {
return gpuTaskList;
}
protected void setGpuTaskList(List<GpuTask> gpuTaskList) {
this.gpuTaskList = gpuTaskList;
}
@Override
public boolean hasGpuTask() {
return !getGpuTaskList().isEmpty();
}
@Override
public GpuTask getNextGpuTask() {
if (hasGpuTask()) {
return getGpuTaskList().remove(0);
}
return null;
}
@Override
public boolean notifyGpuTaskCompletion(GpuTask gt) {
for (ResCloudlet rcl : getCloudletPausedList()) {
ResGpuCloudlet rgcl = (ResGpuCloudlet) rcl;
if (rgcl.getGpuTask() == gt) {
rgcl.setCloudletStatus(GpuCloudlet.SUCCESS);
rgcl.finalizeCloudlet();
return true;
}
}
return false;
}
}
package org.cloudbus.cloudsim.gpu;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.cloudbus.cloudsim.Datacenter;
import org.cloudbus.cloudsim.DatacenterCharacteristics;
import org.cloudbus.cloudsim.Host;
import org.cloudbus.cloudsim.Log;
import org.cloudbus.cloudsim.Storage;
import org.cloudbus.cloudsim.Vm;
import org.cloudbus.cloudsim.VmAllocationPolicy;
import org.cloudbus.cloudsim.core.CloudSim;
import org.cloudbus.cloudsim.core.CloudSimTags;
import org.cloudbus.cloudsim.core.SimEvent;
import org.cloudbus.cloudsim.gpu.core.GpuCloudSimTags;
/**
* {@link GpuDatacenter} extends {@link Datacenter} to support
* {@link GpuCloudlet}s as well as the memory transfer between CPU and GPU.
*
* @author Ahmad Siavashi
*
*/
public class GpuDatacenter extends Datacenter {
private double gpuTaskLastProcessTime;
private Map<GpuTask, ResGpuCloudlet> gpuTaskResGpuCloudletMap;
/**
* See {@link Datacenter#Datacenter}
*/
public GpuDatacenter(String name, DatacenterCharacteristics characteristics, VmAllocationPolicy vmAllocationPolicy,
List<Storage> storageList, double schedulingInterval) throws Exception {
super(name, characteristics, vmAllocationPolicy, storageList, schedulingInterval);
setGpuTaskLastProcessTime(0.0);
setGpuTaskResGpuCloudletMap(new HashMap<>());
}
@Override
public void processEvent(SimEvent ev) {
super.processEvent(ev);
}
@Override
protected void processOtherEvent(SimEvent ev) {
switch (ev.getTag()) {
case GpuCloudSimTags.GPU_MEMORY_TRANSFER:
processGpuMemoryTransfer(ev);
break;
case GpuCloudSimTags.GPU_TASK_SUBMIT:
processGpuTaskSubmit(ev);
break;
case GpuCloudSimTags.GPU_CLOUDLET_RETURN:
processGpuCloudletReturn(ev);
break;
case GpuCloudSimTags.VGPU_DATACENTER_EVENT:
updateGpuTaskProcessing();
checkGpuTaskCompletion();
break;
default:
super.processOtherEvent(ev);
break;
}
}
protected GpuVm getGpuTaskVm(GpuTask gt) {
int userId = gt.getCloudlet().getUserId();
int vmId = gt.getCloudlet().getVmId();
GpuHost host = (GpuHost) getVmAllocationPolicy().getHost(vmId, userId);
GpuVm vm = (GpuVm) host.getVm(vmId, userId);
return vm;
}
protected void notifyGpuTaskCompletion(GpuTask gt) {
GpuVm vm = getGpuTaskVm(gt);
GpuCloudletScheduler scheduler = (GpuCloudletScheduler) vm.getCloudletScheduler();
scheduler.notifyGpuTaskCompletion(gt);
}
protected void processGpuCloudletReturn(SimEvent ev) {
GpuCloudlet cloudlet = (GpuCloudlet) ev.getData();
sendNow(cloudlet.getUserId(), CloudSimTags.CLOUDLET_RETURN, cloudlet);
notifyGpuTaskCompletion(cloudlet.getGpuTask());
}
protected void processGpuMemoryTransfer(SimEvent ev) {
GpuTask gt = (GpuTask) ev.getData();
double bandwidth = Double.valueOf(BusTags.PCI_E_3_X16_BW);
if (gt.getStatus() == GpuTask.CREATED) {
double delay = gt.getTaskInputSize() / bandwidth;
send(getId(), delay, GpuCloudSimTags.GPU_TASK_SUBMIT, gt);
} else if (gt.getStatus() == GpuTask.SUCCESS) {
double delay = gt.getTaskOutputSize() / bandwidth;
send(getId(), delay, GpuCloudSimTags.GPU_CLOUDLET_RETURN, gt.getCloudlet());
}
}
protected void updateGpuTaskProcessing() {
// if some time passed since last processing
// R: for term is to allow loop at simulation start. Otherwise, one initial
// simulation step is skipped and schedulers are not properly initialized
if (CloudSim.clock() < 0.111
|| CloudSim.clock() > geGpuTasktLastProcessTime() + CloudSim.getMinTimeBetweenEvents()) {
List<? extends Host> list = getVmAllocationPolicy().getHostList();
double smallerTime = Double.MAX_VALUE;
// for each host...
for (int i = 0; i < list.size(); i++) {
GpuHost host = (GpuHost) list.get(i);
// inform VMs to update processing
double time = host.updateVgpusProcessing(CloudSim.clock());
// what time do we expect that the next task will finish?
if (time < smallerTime) {
smallerTime = time;
}
}
// guarantees a minimal interval before scheduling the event
if (smallerTime < CloudSim.clock() + CloudSim.getMinTimeBetweenEvents() + 0.01) {
smallerTime = CloudSim.clock() + CloudSim.getMinTimeBetweenEvents() + 0.01;
}
if (smallerTime != Double.MAX_VALUE) {
schedule(getId(), (smallerTime - CloudSim.clock()), GpuCloudSimTags.VGPU_DATACENTER_EVENT);
}
setGpuTaskLastProcessTime(CloudSim.clock());
}
}
protected void checkGpuTaskCompletion() {
List<? extends Host> list = getVmAllocationPolicy().getHostList();
for (int i = 0; i < list.size(); i++) {
GpuHost host = (GpuHost) list.get(i);
for (Vm vm : host.getVmList()) {
GpuVm gpuVm = (GpuVm) vm;
Vgpu vgpu = gpuVm.getVgpu();
if (vgpu != null) {
while (vgpu.getGpuTaskScheduler().hasFinishedTasks()) {
ResGpuTask rgt = vgpu.getGpuTaskScheduler().getNextFinishedTask();
try {
sendNow(getId(), GpuCloudSimTags.GPU_MEMORY_TRANSFER, rgt.getGpuTask());
} catch (Exception e) {
e.printStackTrace();
CloudSim.abruptallyTerminate();
}
}
}
}
}
}
@Override
protected void checkCloudletCompletion() {
super.checkCloudletCompletion();
List<? extends Host> list = getVmAllocationPolicy().getHostList();
for (int i = 0; i < list.size(); i++) {
Host host = list.get(i);
for (Vm vm : host.getVmList()) {
GpuCloudletScheduler scheduler = (GpuCloudletScheduler) vm.getCloudletScheduler();
while (scheduler.hasGpuTask()) {
GpuTask gt = scheduler.getNextGpuTask();
sendNow(getId(), GpuCloudSimTags.GPU_MEMORY_TRANSFER, gt);
}
}
}
}
@Override
protected void processVmCreate(SimEvent ev, boolean ack) {
Vm vm = (Vm) ev.getData();
Log.printLine(CloudSim.clock() + ": Trying to Create VM #" + vm.getId() + " in " + getName());
boolean result = getVmAllocationPolicy().allocateHostForVm(vm);
if (ack) {
int[] data = new int[3];
data[0] = getId();
data[1] = vm.getId();
if (result) {
data[2] = CloudSimTags.TRUE;
} else {
data[2] = CloudSimTags.FALSE;
}
send(vm.getUserId(), CloudSim.getMinTimeBetweenEvents(), CloudSimTags.VM_CREATE_ACK, data);
}
if (result) {
getVmList().add(vm);
GpuVm gpuVm = (GpuVm) vm;
Vgpu vgpu = gpuVm.getVgpu();
if (vm.isBeingInstantiated()) {
vm.setBeingInstantiated(false);
}
vm.updateVmProcessing(CloudSim.clock(),
getVmAllocationPolicy().getHost(vm).getVmScheduler().getAllocatedMipsForVm(vm));
if (vgpu != null) {
if (vgpu.isBeingInstantiated()) {
vgpu.setBeingInstantiated(false);
}
VideoCard videoCard = vgpu.getVideoCard();
vgpu.updateGpuTaskProcessing(CloudSim.clock(),
videoCard.getVgpuScheduler().getAllocatedMipsForVgpu(vgpu));
}
}
}
@Override
protected void processVmDestroy(SimEvent ev, boolean ack) {
GpuVm vm = (GpuVm) ev.getData();
if (vm.hasVgpu()) {
((GpuVmAllocationPolicy) getVmAllocationPolicy()).deallocateGpuForVgpu(vm.getVgpu());
}
super.processVmDestroy(ev, ack);
}
protected void processGpuTaskSubmit(SimEvent ev) {
updateGpuTaskProcessing();
try {
// gets the task object
GpuTask gt = (GpuTask) ev.getData();
// TODO: checks whether this task has finished or not
// process this task to this CloudResource
gt.setResourceParameter(getId(), getCharacteristics().getCostPerSecond(),
getCharacteristics().getCostPerBw());
GpuVm vm = getGpuTaskVm(gt);
Vgpu vgpu = vm.getVgpu();
GpuTaskScheduler scheduler = vgpu.getGpuTaskScheduler();
double estimatedFinishTime = scheduler.taskSubmit(gt);
// if this task is in the exec queue
if (estimatedFinishTime > 0.0 && !Double.isInfinite(estimatedFinishTime)) {
send(getId(), estimatedFinishTime, GpuCloudSimTags.VGPU_DATACENTER_EVENT);
}
} catch (ClassCastException c) {
Log.printLine(getName() + ".processGpuTaskSubmit(): " + "ClassCastException error.");
c.printStackTrace();
} catch (Exception e) {
Log.printLine(getName() + ".processGpuTaskSubmit(): " + "Exception error.");
e.printStackTrace();
System.exit(-1);
}
checkGpuTaskCompletion();
}
protected double geGpuTasktLastProcessTime() {
return gpuTaskLastProcessTime;
}
protected void setGpuTaskLastProcessTime(double lastGpuTaskProcessTime) {
this.gpuTaskLastProcessTime = lastGpuTaskProcessTime;
}
public Map<GpuTask, ResGpuCloudlet> getGpuTaskResGpuCloudletMap() {
return gpuTaskResGpuCloudletMap;
}
protected void setGpuTaskResGpuCloudletMap(Map<GpuTask, ResGpuCloudlet> gpuTaskResGpuCloudletMap) {
this.gpuTaskResGpuCloudletMap = gpuTaskResGpuCloudletMap;
}
}
package org.cloudbus.cloudsim.gpu;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.apache.commons.lang3.NotImplementedException;
import org.cloudbus.cloudsim.Cloudlet;
import org.cloudbus.cloudsim.DatacenterBroker;
import org.cloudbus.cloudsim.DatacenterCharacteristics;
import org.cloudbus.cloudsim.Log;
import org.cloudbus.cloudsim.Vm;
import org.cloudbus.cloudsim.core.CloudSim;
import org.cloudbus.cloudsim.core.CloudSimTags;
import org.cloudbus.cloudsim.core.SimEvent;
import org.cloudbus.cloudsim.core.predicates.PredicateType;
import org.cloudbus.cloudsim.gpu.core.GpuCloudSimTags;
import org.cloudbus.cloudsim.lists.VmList;
/**
* {@link GpuDatacenterBroker} extends {@link DatacenterBroker} to add support
* for GpuCloudlets. Each {@link GpuCloudlet} must have a {@link GpuVm}
* associated with it. If a {@link GpuVm} fails to find a {@link GpuHost} in all
* {@link GpuDatacenter}s, it will be rejected.
*
* @author Ahmad Siavashi
*
*/
public class GpuDatacenterBroker extends DatacenterBroker {
/** A structure to maintain VM-GpuCloudlet mapping */
private HashMap<String, List<GpuCloudlet>> vmGpuCloudletMap;
/** The number of submitted gpuCloudlets in each vm. */
private HashMap<String, Integer> vmGpuCloudletsSubmitted;
/**
* @see DatacenterBroker
*/
public GpuDatacenterBroker(String name) throws Exception {
super(name);
setGpuVmCloudletMap(new HashMap<String, List<GpuCloudlet>>());
setVmGpuCloudletsSubmitted(new HashMap<String, Integer>());
}
@Override
protected void finishExecution() {
for (Integer datacenterId : getDatacenterIdsList()) {
CloudSim.cancelAll(datacenterId.intValue(), new PredicateType(GpuCloudSimTags.VGPU_DATACENTER_EVENT));
}
super.finishExecution();
}
@SuppressWarnings("unchecked")
@Override
protected void createVmsInDatacenter(int datacenterId) {
// send as much vms as possible for this datacenter before trying the
// next one
int requestedVms = 0;
for (GpuVm vm : (List<GpuVm>) (List<?>) getVmList()) {
if (!getVmsToDatacentersMap().containsKey(vm.getId()) && !getVmsCreatedList().contains(vm)) {
getVmsToDatacentersMap().put(vm.getId(), datacenterId);
send(datacenterId, vm.getArrivalTime(), CloudSimTags.VM_CREATE_ACK, vm);
requestedVms++;
}
}
getDatacenterRequestedIdsList().add(datacenterId);
send(datacenterId, CloudSim.getMinTimeBetweenEvents(), GpuCloudSimTags.VGPU_DATACENTER_EVENT);
setVmsRequested(requestedVms);
setVmsAcks(0);
}
@Override
protected void processResourceCharacteristics(SimEvent ev) {
DatacenterCharacteristics characteristics = (DatacenterCharacteristics) ev.getData();
getDatacenterCharacteristicsList().put(characteristics.getId(), characteristics);
if (getDatacenterCharacteristicsList().size() == getDatacenterIdsList().size()) {
setDatacenterRequestedIdsList(new ArrayList<Integer>());
createVmsInDatacenter(getDatacenterIdsList().get(0));
}
}
@Override
protected void processVmCreate(SimEvent ev) {
int[] data = (int[]) ev.getData();
int datacenterId = data[0];
int vmId = data[1];
int result = data[2];
Vm vm = VmList.getById(getVmList(), vmId);
String vmUid = vm.getUid();
if (result == CloudSimTags.TRUE) {
getVmsToDatacentersMap().put(vmId, datacenterId);
getVmsCreatedList().add(vm);
setVmsAcks(getVmsAcks() + 1);
Log.printConcatLine(CloudSim.clock(), ": ", getName(), ": VM #", vmId, " has been created in Datacenter #",
datacenterId, ", Host #", vm.getHost().getId());
System.out.println("{'clock': " + CloudSim.clock() + ", 'type': 'vm allocation', 'vm': " + vm.getId()
+ ", 'host': " + vm.getHost().getId() + "}");
Vgpu vgpu = ((GpuVm) vm).getVgpu();
if (vgpu != null) {
Pgpu pgpu = vgpu.getVideoCard().getVgpuScheduler().getPgpuForVgpu(vgpu);
System.out.println("{'clock': " + CloudSim.clock() + ", 'type': 'vgpu allocation', 'vgpu': "
+ vgpu.getId() + ", 'pgpu': " + pgpu.getId() + ", 'vm': " + vm.getId() + "}");
}
// VM has been created successfully, submit its cloudlets now.
List<GpuCloudlet> vmCloudlets = getVmGpuCloudletMap().get(vmUid);
for (GpuCloudlet cloudlet : vmCloudlets) {
submitGpuCloudlet(cloudlet);
}
getVmGpuCloudletsSubmitted().put(vmUid, vmCloudlets.size());
// Remove submitted cloudlets from queue
getCloudletList().removeAll(vmCloudlets);
getVmGpuCloudletMap().get(vmUid).removeAll(vmCloudlets);
getVmGpuCloudletMap().remove(vmUid);
} else {
Log.printConcatLine(CloudSim.clock(), ": ", getName(), ": Creation of VM #", vmId,
" failed in Datacenter #", datacenterId);
// Create the VM in another datacenter.
int nextDatacenterId = getDatacenterIdsList()
.get((getDatacenterIdsList().indexOf(datacenterId) + 1) % getDatacenterIdsList().size());
if (!getDatacenterRequestedIdsList().contains(nextDatacenterId)) {
getDatacenterRequestedIdsList().add(nextDatacenterId);
send(nextDatacenterId, CloudSim.getMinTimeBetweenEvents(), GpuCloudSimTags.VGPU_DATACENTER_EVENT);
}
// Check for looping datacenters
if (getDatacenterIdsList().indexOf(nextDatacenterId) != 0) {
getVmsToDatacentersMap().replace(vmId, nextDatacenterId);
send(nextDatacenterId, CloudSim.getMinTimeBetweenEvents(), CloudSimTags.VM_CREATE_ACK, vm);
} else {
// Reject the VM
System.out.println(
"{'clock': " + CloudSim.clock() + ", 'type': 'vm rejection', 'vm': " + vm.getId() + "}");
List<GpuCloudlet> vmCloudlets = getVmGpuCloudletMap().get(vmUid);
getCloudletList().removeAll(vmCloudlets);
getVmGpuCloudletMap().get(vmUid).removeAll(vmCloudlets);
getVmGpuCloudletMap().remove(vmUid);
}
}
}
protected void processVmDestroy(SimEvent ev) {
int[] data = (int[]) ev.getData();
int datacenterId = data[0];
int vmId = data[1];
int result = data[2];
if (result == CloudSimTags.TRUE) {
Log.printLine(CloudSim.clock() + ": VM #" + vmId + " destroyed in Datacenter #" + datacenterId);
System.out.println("{'clock': " + CloudSim.clock() + ", 'type': 'vm deallocation', 'vm': " + vmId + "}");
setVmsDestroyed(getVmsDestroyed() + 1);
getVmGpuCloudletsSubmitted().remove(Vm.getUid(getId(), vmId));
} else {
Log.printLine(CloudSim.clock() + ": Failed to destroy VM #" + vmId + " in Datacenter #" + datacenterId);
}
}
@Override
protected void processCloudletReturn(SimEvent ev) {
Cloudlet cloudlet = (Cloudlet) ev.getData();
getCloudletReceivedList().add(cloudlet);
Log.printConcatLine(CloudSim.clock(), ": ", getName(), ": Cloudlet ", cloudlet.getCloudletId(), " received");
GpuVm cloudletVm = (GpuVm) VmList.getByIdAndUserId(getVmList(), cloudlet.getVmId(), getId());
getVmGpuCloudletsSubmitted().replace(cloudletVm.getUid(),
getVmGpuCloudletsSubmitted().get(cloudletVm.getUid()) - 1);
cloudletsSubmitted--;
if (getVmGpuCloudletsSubmitted().get(cloudletVm.getUid()) == 0) {
sendNow(getVmsToDatacentersMap().get(cloudlet.getVmId()), CloudSimTags.VM_DESTROY_ACK, cloudletVm);
getVmsCreatedList().remove(cloudletVm);
}
// all cloudlets executed
if (getCloudletList().isEmpty() && cloudletsSubmitted == 0) {
Log.printConcatLine(CloudSim.clock(), ": ", getName(), ": All Jobs executed. Finishing...");
clearDatacenters();
finishExecution();
}
}
@Override
protected void processOtherEvent(SimEvent ev) {
switch (ev.getTag()) {
// VM Destroy answer
case CloudSimTags.VM_DESTROY_ACK:
processVmDestroy(ev);
break;
default:
super.processOtherEvent(ev);
break;
}
}
protected void submitGpuCloudlet(GpuCloudlet gpuCloudlet) {
int datacenterId = getVmsToDatacentersMap().get(gpuCloudlet.getVmId());
sendNow(datacenterId, CloudSimTags.CLOUDLET_SUBMIT, gpuCloudlet);
getCloudletSubmittedList().add(gpuCloudlet);
cloudletsSubmitted++;
}
@Override
public void bindCloudletToVm(int cloudletId, int vmId) {
throw new NotImplementedException("not implemented");
}
@Override
public void submitCloudletList(List<? extends Cloudlet> list) {
getCloudletList().addAll(list);
if (getVmList().isEmpty()) {
throw new IllegalArgumentException("no vm submitted.");
}
for (Cloudlet cloudlet : getCloudletList()) {
if (cloudlet.getVmId() < 0) {
throw new IllegalArgumentException("cloudlet (#" + cloudlet.getCloudletId() + ") has no VM.");
}
Vm vm = VmList.getById(getVmList(), cloudlet.getVmId());
if (vm == null) {
throw new IllegalArgumentException("no such vm (Id #" + cloudlet.getVmId() + ") exists for cloudlet (#"
+ cloudlet.getCloudletId() + ")");
}
getVmGpuCloudletMap().get(vm.getUid()).add((GpuCloudlet) cloudlet);
}
}
@Override
public void submitVmList(List<? extends Vm> list) {
super.submitVmList(list);
for (Vm vm : vmList) {
if (!getVmGpuCloudletMap().containsKey(vm.getUid())) {
getVmGpuCloudletMap().put(vm.getUid(), new ArrayList<>());
}
}
}
/**
* @return the vmGpuCloudletsSubmitted
*/
protected HashMap<String, Integer> getVmGpuCloudletsSubmitted() {
return vmGpuCloudletsSubmitted;
}
/**
* @param vmGpuCloudletsSubmitted the vmGpuCloudletsSubmitted to set
*/
protected void setVmGpuCloudletsSubmitted(HashMap<String, Integer> vmGpuCloudletsSubmitted) {
this.vmGpuCloudletsSubmitted = vmGpuCloudletsSubmitted;
}
/**
* @return the vmGpuCloudletMap
*/
protected HashMap<String, List<GpuCloudlet>> getVmGpuCloudletMap() {
return vmGpuCloudletMap;
}
/**
* @param vmGpuCloudletMap the vmGpuCloudletMap to set
*/
protected void setGpuVmCloudletMap(HashMap<String, List<GpuCloudlet>> vmGpuCloudletMap) {
this.vmGpuCloudletMap = vmGpuCloudletMap;
}
}
package org.cloudbus.cloudsim.gpu;
import java.util.List;
import java.util.Set;
import org.cloudbus.cloudsim.Host;
import org.cloudbus.cloudsim.Pe;
import org.cloudbus.cloudsim.VmScheduler;
import org.cloudbus.cloudsim.gpu.allocation.VideoCardAllocationPolicy;
import org.cloudbus.cloudsim.provisioners.BwProvisioner;
import org.cloudbus.cloudsim.provisioners.RamProvisioner;
/**
*
* {@link GpuHost} extends {@link Host} and supports {@link VideoCard}s through
* a {@link VideoCardAllocationPolicy}.
*
* @author Ahmad Siavashi
*
*/
public class GpuHost extends Host {
/**
* type of the host
*/
public String type;
/** video card allocation policy */
private VideoCardAllocationPolicy videoCardAllocationPolicy;
/**
*
* See {@link Host#Host}
*
* @param type type of the host which is specified in
* {@link GpuHostTags}.
* @param videoCardAllocationPolicy the policy in which the host allocates video
* cards to vms
*/
public GpuHost(int id, String type, RamProvisioner ramProvisioner, BwProvisioner bwProvisioner, long storage,
List<? extends Pe> peList, VmScheduler vmScheduler, VideoCardAllocationPolicy videoCardAllocationPolicy) {
super(id, ramProvisioner, bwProvisioner, storage, peList, vmScheduler);
setType(type);
setVideoCardAllocationPolicy(videoCardAllocationPolicy);
}
/**
*
* See {@link Host#Host}
*
* @param type type of the host which is specified in {@link GpuHostTags}.
*/
public GpuHost(int id, String type, RamProvisioner ramProvisioner, BwProvisioner bwProvisioner, long storage,
List<? extends Pe> peList, VmScheduler vmScheduler) {
super(id, ramProvisioner, bwProvisioner, storage, peList, vmScheduler);
setType(type);
setVideoCardAllocationPolicy(null);
}
public double updateVgpusProcessing(double currentTime) {
double smallerTime = Double.MAX_VALUE;
if (getVideoCardAllocationPolicy() != null) {
// Update resident vGPUs
for (Vgpu vgpu : getVideoCardAllocationPolicy().getVgpuVideoCardMap().keySet()) {
double time = vgpu.updateGpuTaskProcessing(currentTime, getVideoCardAllocationPolicy()
.getVgpuVideoCardMap().get(vgpu).getVgpuScheduler().getAllocatedMipsForVgpu(vgpu));
if (time > 0.0 && time < smallerTime) {
smallerTime = time;
}
}
}
return smallerTime;
}
/**
* @return the videoCardAllocationPolicy
*/
public VideoCardAllocationPolicy getVideoCardAllocationPolicy() {
return videoCardAllocationPolicy;
}
/**
* @param videoCardAllocationPolicy the videoCardAllocationPolicy to set
*/
public void setVideoCardAllocationPolicy(VideoCardAllocationPolicy videoCardAllocationPolicy) {
this.videoCardAllocationPolicy = videoCardAllocationPolicy;
}
/**
* Checks the existence of a given video card id in the host
*
* @param videoCardId id of the video card
* @return
*/
public boolean hasVideoCard(int videoCardId) {
if (getVideoCardAllocationPolicy() == null || getVideoCardAllocationPolicy().getVideoCards().isEmpty()) {
return false;
}
for (VideoCard videoCard : getVideoCardAllocationPolicy().getVideoCards()) {
if (videoCard.getId() == videoCardId) {
return true;
}
}
return false;
}
/**
* Checks the existence of a given pgpu id in the host
*
* @param pgpuId id of the video card
* @return
*/
public boolean hasPgpu(int pgpuId) {
if (getVideoCardAllocationPolicy() == null || getVideoCardAllocationPolicy().getVideoCards().isEmpty()) {
return false;
}
for (VideoCard videoCard : getVideoCardAllocationPolicy().getVideoCards()) {
for (Pgpu pgpu : videoCard.getVgpuScheduler().getPgpuList()) {
if (pgpu.getId() == pgpuId) {
return true;
}
}
}
return false;
}
public void vgpuDestroy(Vgpu vgpu) {
if (vgpu != null) {
getVideoCardAllocationPolicy().deallocate(vgpu);
}
}
public boolean vgpuCreate(Vgpu vgpu) {
return getVideoCardAllocationPolicy().allocate(vgpu, vgpu.getPCIeBw());
}
public boolean vgpuCreate(Vgpu vgpu, Pgpu pgpu) {
return getVideoCardAllocationPolicy().allocate(pgpu, vgpu, vgpu.getPCIeBw());
}
/**
* @return the type
*/
public String getType() {
return type;
}
/**
* @param type the type to set
*/
protected void setType(String type) {
this.type = type;
}
public Set<Vgpu> getVgpuSet() {
if (getVideoCardAllocationPolicy() == null) {
return null;
} else if (getVideoCardAllocationPolicy().getVideoCards().isEmpty()) {
return null;
}
return getVideoCardAllocationPolicy().getVgpuVideoCardMap().keySet();
}
public boolean isIdle() {
if (!getVmList().isEmpty()) {
return false;
} else if (getVgpuSet() != null && !getVgpuSet().isEmpty()) {
return false;
}
return true;
}
}
package org.cloudbus.cloudsim.gpu;
import org.cloudbus.cloudsim.gpu.hardware_assisted.GridVideoCardTags;
/**
*
* Methods & constants that are related to {@link GpuHost GpuHosts} types and configurations.
*
* @author Ahmad Siavashi
*
*/
public class GpuHostTags {
// Host Types
public final static String HOST_CUSTOM = "Custom";
public final static String DUAL_INTEL_XEON_E5_2620_V3 = "Dual Intel Xeon E5-2620 v3 (12 Cores, 2.40 GHz, 1 x NVIDIA GRID K1)";
public final static String DUAL_INTEL_XEON_E5_2690_V4 = "Dual Intel Xeon E5-2690 v4 (28 Cores, 2.60 GHz, 1 x NVIDIA GRID K2)";
// Instruction per Cycle (IPC)
private final static int INTEL_XEON_E5_2600_V3_V4_IPC = 16;
// 25 Gbit/s in MB/s
public final static int NETWORK_BANDWIDTH_25_GBIT_PER_SEC = 3125;
// Dual Intel Xeon E5-2620 v3
/** 12 Cores */
public final static int DUAL_INTEL_XEON_E5_2620_V3_NUM_PES = 12;
/** Dual Intel Xeon E5-2620 v3 (2.4 GHz) */
public final static double DUAL_INTEL_XEON_E5_2620_V3_PE_MIPS = 2400 * INTEL_XEON_E5_2600_V3_V4_IPC;
/** 64GB RAM */
public final static int DUAL_INTEL_XEON_E5_2620_V3_RAM = 64 * 1024;
/** 1 x 1TB SATA Local Storage */
public final static int DUAL_INTEL_XEON_E5_2620_V3_STORAGE = 1024 * 1024;
/** 25 GB/s */
public final static int DUAL_INTEL_XEON_E5_2620_V3_BW = NETWORK_BANDWIDTH_25_GBIT_PER_SEC;
/** 1 Video Card Per GPU Host */
public final static int DUAL_INTEL_XEON_E5_2620_V3_NUM_VIDEO_CARDS = 1;
/** 1 NVIDIA Grid K1 Per Host */
public final static String DUAL_INTEL_XEON_E5_2620_V3_VIDEO_CARD = GridVideoCardTags.NVIDIA_K1_CARD;
// Dual Intel Xeon E5-2690 v4
/** 28 Cores */
public final static int DUAL_INTEL_XEON_E5_2690_V4_NUM_PES = 28;
/** Dual Intel Xeon E5-2690 v4 (2.6 GHz) */
public final static double DUAL_INTEL_XEON_E5_2690_V4_PE_MIPS = 2600 * INTEL_XEON_E5_2600_V3_V4_IPC;
/** 128GB RAM */
public final static int DUAL_INTEL_XEON_E5_2690_V4_RAM = 128 * 1024;
/** 2 x 4TB SATA Local Storage */
public final static int DUAL_INTEL_XEON_E5_2690_V4_STORAGE = 2 * 4096 * 1024;
/** 25 GB/s */
public final static int DUAL_INTEL_XEON_E5_2690_V4_BW = NETWORK_BANDWIDTH_25_GBIT_PER_SEC;
/** 1 Video Card Per GPU Host */
public final static int DUAL_INTEL_XEON_E5_2690_V4_NUM_VIDEO_CARDS = 1;
/** 1 NVIDIA Grid K2 Per Host */
public final static String DUAL_INTEL_XEON_E5_2690_V4_VIDEO_CARD = GridVideoCardTags.NVIDIA_K2_CARD;
}
package org.cloudbus.cloudsim.gpu;
import org.cloudbus.cloudsim.CloudletScheduler;
import org.cloudbus.cloudsim.Vm;
/**
*
* {@link GpuVm} extends {@link Vm} to represent a VM with GPU requirements.
*
* @author Ahmad Siavashi
*
*/
public class GpuVm extends Vm {
/**
* Describes vm's type. A type can be associated with a configuration, therefore
* it helps identifying the vm
*/
private String type;
/**
* Denotes the time in which the VM enters the system.
*/
private double arrivalTime;
/** The Vgpu associated with the Vm */
private Vgpu vgpu;
/**
* @see Vm
* @param vgpu
* the vgpu associated with this VM. Pass null in case of no vgpu.
* @param type
* specifies the type of the vm
*/
public GpuVm(int id, int userId, double mips, int numberOfPes, int ram, long bw, long size, String vmm, String type,
CloudletScheduler cloudletScheduler) {
super(id, userId, mips, numberOfPes, ram, bw, size, vmm, cloudletScheduler);
setType(type);
setArrivalTime(0.0);
}
/**
* @return the type
*/
public String getType() {
return type;
}
/**
* @param type
* the type to set
*/
protected void setType(String type) {
this.type = type;
}
/**
* @return the vgpu
*/
public Vgpu getVgpu() {
return vgpu;
}
/**
* @param vgpu
* the vgpu to set
*/
public void setVgpu(Vgpu vgpu) {
this.vgpu = vgpu;
if (vgpu.getVm() == null) {
vgpu.setGpuVm(this);
}
}
public boolean hasVgpu() {
return getVgpu() != null;
}
public double getArrivalTime() {
return arrivalTime;
}
public void setArrivalTime(double arrivalTime) {
this.arrivalTime = arrivalTime;
}
}
package org.cloudbus.cloudsim.gpu;
import org.cloudbus.cloudsim.VmStateHistoryEntry;
/**
* @author Ahmad Siavashi
*
*/
public class VgpuStateHistoryEntry extends VmStateHistoryEntry {
/**
* @see VmStateHistoryEntry#VmStateHistoryEntry
*/
public VgpuStateHistoryEntry(double time, double allocatedMips,
double requestedMips, boolean isInMigration) {
super(time, allocatedMips, requestedMips, isInMigration);
}
}
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