Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions core/src/main/java/matrixstudio/kernel/CLUtil.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package matrixstudio.kernel;

import matrixstudio.model.Device;
import matrixstudio.model.PlatformCL;

import org.jocl.CL;
import org.jocl.Pointer;
import org.jocl.cl_device_id;
Expand Down Expand Up @@ -155,8 +157,48 @@ public static Device getDevice(cl_device_id device) {
}
}

/**
* Get list of platform
* @return
*/

public static List<cl_platform_id> getListPlatform(){
List<cl_platform_id> listPlatform = new ArrayList<>();

int numPlatforms[] = new int[1];
clGetPlatformIDs(0, null, numPlatforms);

// Obtain the platform IDs
cl_platform_id platforms[] = new cl_platform_id[numPlatforms[0]];
clGetPlatformIDs(platforms.length, platforms, null);

listPlatform.addAll(Arrays.asList(platforms));

return listPlatform;

}

/**
* Get platform by platformId
* @param platformId
* @return
*/

public static PlatformCL getPlatform(cl_platform_id platformId) {

PlatformCL res = new PlatformCL(platformId);

return res;
}

public static void main(String[] args) {
cl_device_id id = selectHardware(Device.CPU).get(0);
System.out.println(getLong(id, CL.CL_DEVICE_MAX_WORK_GROUP_SIZE));

List<cl_platform_id> list = getListPlatform();

for(int i = 0; i < list.size(); i++) {
System.out.println(list.get(i));
}
}
}
24 changes: 19 additions & 5 deletions core/src/main/java/matrixstudio/kernel/Simulator.java
Original file line number Diff line number Diff line change
Expand Up @@ -254,12 +254,28 @@ private void initMatrices() {
}

private void initCL() throws EvaluationException, ParseException {
final Model model = getModel();
final Scheduler scheduler = model.getScheduler();

long numBytes[] = new long[1];

// Creation of an OpenCL context on GPU
log.log("Obtaining platform...");
cl_platform_id platforms[] = new cl_platform_id[1];
clGetPlatformIDs(platforms.length, platforms, null);
cl_platform_id platforms[];

//Condition if platform IDs is null or not
if(scheduler.getPlatform().getPlatformId() != null) {
platforms = new cl_platform_id[1];
platforms[0] = scheduler.getPlatform().getPlatformId();

}else {

platforms = new cl_platform_id[1];
clGetPlatformIDs(platforms.length, platforms, null);
}



if(platforms[0]==null) {
throw new CLException("No OpenCL plateform found. Impossible to compile the code.");
} else {
Expand All @@ -272,8 +288,6 @@ private void initCL() throws EvaluationException, ParseException {
// Enable exceptions and subsequently get error checks
CL.setExceptionsEnabled(true);

final Model model = getModel();
final Scheduler scheduler = model.getScheduler();

// checks if device exist
final List<cl_device_id> hardwareList = CLUtil.selectHardware(scheduler.getDevice());
Expand Down
79 changes: 79 additions & 0 deletions core/src/main/java/matrixstudio/model/PlatformCL.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package matrixstudio.model;

import java.util.ArrayList;
import java.util.List;

import org.jocl.cl_platform_id;

import matrixstudio.kernel.CLUtil;

/**
* <b>Classe Platform<b>
* <p>The Platform class is used to retrieve the platform id<p>
*
* @author lesech
*/

/**
*
*/

public class PlatformCL {

/**
* platform id
*
* @see PlatformCL#getPlatformId()
* @see PlatformCL#setPlatformId(cl_platform_id)
* @see PlatformCL#setPlatformId(int)
*/
private cl_platform_id platformId;

/**
* Constructor of the Platform class with a variable of type cl_platform as parameter
* @param platformId
*/

public PlatformCL(cl_platform_id platformId) {
this.platformId = platformId;
}

/**
*
* <p>Default constructor of the platform class<p>
*/
public PlatformCL() {
this.platformId = null;
}

/**
* get platform id's
* @return
*/
public cl_platform_id getPlatformId() {
return this.platformId;
}

/**
* set platform Id
* @param platformId
*/

public void setPlatformId(cl_platform_id platformId) {
this.platformId = platformId;
}

/**
* set platformId with Index
* @param index
*/

public void setPlatformId(int index) {
List<cl_platform_id> listPlatform = CLUtil.getListPlatform();
cl_platform_id res = listPlatform.get(index);

this.platformId = res;

}

}
29 changes: 29 additions & 0 deletions core/src/main/java/matrixstudio/model/Scheduler.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public class Scheduler implements ModelObject, BoostObject {
private final List<Task> taskList = new ArrayList<Task>();

private Device device = Device.ANY;

private PlatformCL platform = new PlatformCL();

private int deviceOrder = 1;

Expand Down Expand Up @@ -208,6 +210,7 @@ public void setDevice(Device newValue) {
this.device= newValue;
}
}


/**
* <p>Gets deviceOrder.</p>
Expand All @@ -226,6 +229,32 @@ public void setDeviceOrder(int newValue) {
}
}


/**
* set platform
* @param platform
*/

public void setPlatform(PlatformCL platform) {
this.platform = platform;
}

/**
* set platform with index
* @param index
*/
public void setPlatform(int index) {
this.platform.setPlatformId(index);
}

/**
* get platform attribut
* @return platform
*/
public PlatformCL getPlatform() {
return this.platform;
}

public void writeToBoost(Boost boost) {
boost.writeObject(model);
BoostUtil.writeObjectCollection(boost, taskList);
Expand Down
21 changes: 21 additions & 0 deletions core/src/test/java/matrixstudio/model/ModelTest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package matrixstudio.model;

import java.io.File;
import java.util.List;

import matrixstudio.kernel.CLUtil;
import matrixstudio.kernel.Tools;

import org.jocl.cl_platform_id;
import org.junit.Assert;
import org.junit.Test;

Expand All @@ -25,6 +30,22 @@ public void test1() throws Exception {
Assert.assertEquals(1, loaded.getScheduler().getTaskCount());

}

@Test
public void testTaillePlatform() {
List<cl_platform_id> listPlatform = CLUtil.getListPlatform();

Assert.assertEquals(1, listPlatform.size());
}

@Test
public void testInstanceof() {
List<cl_platform_id> listPlatform = CLUtil.getListPlatform();

for(int i = 0; i < listPlatform.size(); i++) {
Assert.assertTrue(listPlatform.get(i) instanceof cl_platform_id);
}
}

private Model createModel() {
Model model = new Model();
Expand Down