Allow the user to configure the GPU render bucket size (#220)

* Feature: user defined render bucket size when using GPUs
This commit is contained in:
Luis Uguina
2020-05-16 18:20:38 +10:00
committed by GitHub
parent 36e32ab168
commit bd88b2e3dd
9 changed files with 255 additions and 15 deletions

View File

@@ -19,10 +19,14 @@
package com.sheepit.client.hardware.gpu;
import com.sheepit.client.hardware.gpu.nvidia.Nvidia;
import com.sheepit.client.hardware.gpu.opencl.OpenCL;
public class GPUDevice {
private String type;
private String model;
private long memory; // in B
private int renderBucketSize;
private String id;
@@ -33,6 +37,7 @@ public class GPUDevice {
this.model = model;
this.memory = ram;
this.id = id;
this.renderBucketSize = 32;
}
public GPUDevice(String type, String model, long ram, String id, String oldId) {
@@ -80,8 +85,43 @@ public class GPUDevice {
this.oldId = id;
}
public int getRenderbucketSize() {
return this.renderBucketSize;
}
public void setRenderbucketSize(int proposedRenderbucketSize) {
int renderBucketSize = 32;
GPULister gpu;
if (type.equals("CUDA")) {
gpu = new Nvidia();
}
else if (type.equals("OPENCL")) {
gpu = new OpenCL();
}
else {
// If execution takes this branch is because we weren't able to detect the proper GPU technology or
// because is a new one (different from CUDA and OPENCL). In that case, move into the safest position
// of 32x32 pixel tile sizes
System.out.println("GPUDevice::setRenderbucketSize Unable to detect GPU technology. Render bucket size set to 32x32 pixels");
this.renderBucketSize = 32;
return;
}
if (proposedRenderbucketSize >= 32) {
if (proposedRenderbucketSize <= gpu.getMaximumRenderBucketSize(getMemory())) {
renderBucketSize = proposedRenderbucketSize;
}
else {
renderBucketSize = gpu.getRecommendedRenderBucketSize(getMemory());
}
}
this.renderBucketSize = renderBucketSize;
}
@Override
public String toString() {
return "GPUDevice [type=" + type + ", model='" + model + "', memory=" + memory + ", id=" + id + "]";
return "GPUDevice [type=" + type + ", model='" + model + "', memory=" + memory + ", id=" + id + ", renderbucketSize=" + renderBucketSize + "]";
}
}

View File

@@ -4,4 +4,8 @@ import java.util.List;
public interface GPULister {
public abstract List<GPUDevice> getGpus();
public abstract int getRecommendedRenderBucketSize(long memory);
public abstract int getMaximumRenderBucketSize(long memory);
}

View File

@@ -127,4 +127,14 @@ public class Nvidia implements GPULister {
return devices;
}
@Override
public int getRecommendedRenderBucketSize(long memory) {
// Optimal CUDA-based GPUs Renderbucket algorithm
return (memory > 1073741824L) ? 256 : 128;
}
@Override
public int getMaximumRenderBucketSize(long memory) {
return (memory > 1073741824L) ? 512 : 128;
}
}

View File

@@ -123,6 +123,17 @@ public class OpenCL implements GPULister {
return available_devices;
}
@Override
public int getRecommendedRenderBucketSize(long memory) {
// Optimal CUDA-based GPUs Renderbucket algorithm
return (memory > 1073741824L) ? 256 : 128;
}
@Override
public int getMaximumRenderBucketSize(long memory) {
return (memory > 1073741824L) ? 2048 : 128;
}
private static String getInfodeviceString(OpenCLLib lib, CLDeviceId.ByReference device, int type) {
byte name[] = new byte[256];