Refactor createDeviceBuffer
@@ -294,11 +294,8 @@ public class OCLTornadoDevice implements TornadoAcceleratorDevice {
}
}
- private ObjectBuffer createDeviceBuffer(Class<?> type, Object arg, OCLDeviceContext device) throws TornadoOutOfMemoryException {
+ private ObjectBuffer createArrayWrapper(Class<?> type, OCLDeviceContext device) {
ObjectBuffer result = null;
- if (type.isArray()) {
-
- if (!type.getComponentType().isArray()) {
if (type == int[].class) {
result = new OCLIntArrayWrapper(device);
} else if (type == short[].class) {
@@ -316,9 +313,12 @@ public class OCLTornadoDevice implements TornadoAcceleratorDevice {
} else {
TornadoInternalError.unimplemented("array of type %s", type.getName());
}
- } else {
- final Class<?> componentType = type.getComponentType();
- if (RuntimeUtilities.isPrimitiveArray(componentType)) {
+ return result;
+ }
+
+ private ObjectBuffer createMultiArrayWrapper(Class<?> componentType, Class<?> type, OCLDeviceContext device) {
+ ObjectBuffer result = null;
+
if (componentType == int[].class) {
result = new OCLMultiDimArrayWrapper<>(device, (OCLDeviceContext context) -> new OCLIntArrayWrapper(context));
} else if (componentType == short[].class) {
@@ -336,6 +336,19 @@ public class OCLTornadoDevice implements TornadoAcceleratorDevice {
} else {
TornadoInternalError.unimplemented("array of type %s", type.getName());
}
+ return result;
+ }
+
+ private ObjectBuffer createDeviceBuffer(Class<?> type, Object arg, OCLDeviceContext device) throws TornadoOutOfMemoryException {
+ ObjectBuffer result = null;
+ if (type.isArray()) {
+
+ if (!type.getComponentType().isArray()) {
+ result = createArrayWrapper(type, device);
+ } else {
+ final Class<?> componentType = type.getComponentType();
+ if (RuntimeUtilities.isPrimitiveArray(componentType)) {
+ result = createMultiArrayWrapper(componentType, type, device);
} else {
TornadoInternalError.unimplemented("multi-dimensional array of type %s", type.getName());
}
