Skip to content

Commit

Permalink
[GrCUDA-66] fix arity deprecation (#27)
Browse files Browse the repository at this point in the history
* removed deprecation warning for arity exception

* updated changelog
  • Loading branch information
AlbertoParravicini authored Dec 11, 2021
1 parent f6a457d commit 920f52c
Show file tree
Hide file tree
Showing 15 changed files with 51 additions and 41 deletions.
12 changes: 6 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# 2021-11-29

* Removed deprecation warning for Truffle's ArityException.

# 2021-11-21

* Enabled support for cuSPARSE
* Operations with sparse matrices from cuSPARSE library are now supported
* **Known limitation:** Not all data types are supported: in particular Tgemvi does not support double data types
(both complex and not)
* Concurrent operations on parallel streams were analyzed using Nvidia Profiler

=======
* Added support for CSR and COO `spmv` and `gemvi`.
* **Known limitation:** Tgemvi works only with single-precision floating-point arithmetics.

# 2021-11-17

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public Object call(Object[] arguments) throws ArityException {
@TruffleBoundary
public Object call(Object[] arguments) throws ArityException {
checkArgumentLength(arguments, 2);
try (UnsafeHelper.Integer64Object handle = UnsafeHelper.createInteger64Object()) {
try {
long stream_handle = expectLong(arguments[0]);
long streamID = expectLong(arguments[1]);
Object result = INTEROP.execute(cumlSetStreamFunctionNFI, stream_handle, streamID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ Object execute(Object[] arguments,
numElements = extractNumber(arguments[1], numElementsAccess);
} else {
CompilerDirectives.transferToInterpreter();
throw ArityException.create(1, arguments.length);
throw ArityException.create(1, 2, arguments.length);
}
// Obtain what kind of copy (pointer or array) should be executed.
// By default, see if we can use the fast CUDA memcpy: we cannot use it if the source and target arrays
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public DeviceArrayFunction(AbstractGrCUDAExecutionContext grCUDAExecutionContext
@TruffleBoundary
public Object call(Object[] arguments) throws ArityException, UnsupportedTypeException {
if (arguments.length < 1) {
throw ArityException.create(1, arguments.length);
throw ArityException.create(1, 2, arguments.length);
}
String typeName = expectString(arguments[0], "first argument of DeviceArray must be string (type name)");
Type elementType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,14 @@ public static long expectPositiveLong(Object number) throws UnsupportedTypeExcep
public static void checkArgumentLength(Object[] arguments, int expected) throws ArityException {
if (arguments.length != expected) {
CompilerDirectives.transferToInterpreter();
throw ArityException.create(expected, arguments.length);
throw ArityException.create(expected, expected, arguments.length);
}
}

public static void checkArgumentLength(Object[] arguments, int minExpected, int maxExpected) throws ArityException {
if (arguments.length < minExpected || arguments.length > maxExpected) {
CompilerDirectives.transferToInterpreter();
throw ArityException.create(minExpected, maxExpected, arguments.length);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ public Object execute(Object[] arguments,
@Cached MapArrayNode mapNode) throws ArityException, UnsupportedTypeException {
if (arguments.length < 1) {
CompilerDirectives.transferToInterpreter();
throw ArityException.create(1, arguments.length);
throw ArityException.create(1, 2, arguments.length);
}
String typeName;
try {
Expand All @@ -244,12 +244,11 @@ public Object execute(Object[] arguments,
}
if (arguments.length == 1) {
return new TypedMapDeviceArrayFunction(grCUDAExecutionContext, elementType);
} else {
if (arguments.length != 2) {
CompilerDirectives.transferToInterpreter();
throw ArityException.create(2, arguments.length);
}
} else if (arguments.length == 2) {
return mapNode.execute(arguments[1], elementType, grCUDAExecutionContext);
} else {
CompilerDirectives.transferToInterpreter();
throw ArityException.create(1, 2, arguments.length);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ public TypedDeviceArrayFunction(AbstractGrCUDAExecutionContext grCUDAExecutionCo
public Object call(Object[] arguments) throws ArityException, UnsupportedTypeException {
if (arguments.length < 1) {
CompilerDirectives.transferToInterpreter();
throw ArityException.create(1, arguments.length);
// FIXME: the maximum number of arguments is unbound (as each argument is a dimension of a N-dimensional tensor).
// Truffle currently uses -1 to handle an unbound number of arguments;
throw ArityException.create(1, -1, arguments.length);
}
return DeviceArrayFunction.createArray(arguments, 0, elementType, grCUDAExecutionContext);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public Object execute(Object[] arguments,
@Cached MapArrayNode mapNode) throws ArityException {
if (arguments.length != 1) {
CompilerDirectives.transferToInterpreter();
throw ArityException.create(1, arguments.length);
throw ArityException.create(1, 1, arguments.length);
}
return mapNode.execute(arguments[0], elementType, grCUDAExecutionContext);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public MappedFunction map(Object function, Object... arguments) throws ArityExce
static void checkArity(Object[] arguments, int expectedArity) throws ArityException {
if (arguments.length != expectedArity) {
CompilerDirectives.transferToInterpreter();
throw ArityException.create(expectedArity, arguments.length);
throw ArityException.create(expectedArity, expectedArity, arguments.length);
}
}

Expand Down Expand Up @@ -175,7 +175,9 @@ static MapFunctionBase readMemberArg(MapFunction receiver, String member) {
static MapFunctionBase readMemberSize(MapFunction receiver, String member) {
return new MapFunctionBase(arguments -> {
if (arguments.length == 0) {
throw ArityException.create(1, 0);
// FIXME: the maximum number of arguments is unbound.
// Truffle currently uses -1 to handle an unbound number of arguments;
throw ArityException.create(1, -1, 0);
}
try {
return receiver.size((MapArgObject) arguments[0], Arrays.copyOfRange(arguments, 1, arguments.length, MapArgObject[].class));
Expand All @@ -189,7 +191,9 @@ static MapFunctionBase readMemberSize(MapFunction receiver, String member) {
static MapFunctionBase readMemberValue(MapFunction receiver, String member) {
return new MapFunctionBase(arguments -> {
if (arguments.length < 1) {
throw ArityException.create(1, arguments.length);
// FIXME: the maximum number of arguments is unbound.
// Truffle currently uses -1 to handle an unbound number of arguments;
throw ArityException.create(1, -1, arguments.length);
}
String name = checkString(arguments[0], "name of created value expected");
if (arguments.length == 1) {
Expand Down Expand Up @@ -225,7 +229,9 @@ Object invokeMember(String member, Object[] arguments,
@TruffleBoundary
public MappedFunction execute(Object[] arguments) throws ArityException, UnsupportedTypeException {
if (arguments.length == 0) {
throw ArityException.create(1, 0);
// FIXME: the maximum number of arguments is unbound.
// Truffle currently uses -1 to handle an unbound number of arguments;
throw ArityException.create(1, -1, 0);
}
Object function = arguments[0];
if (!INTEROP.isExecutable(function)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ long execute(Object[] arguments,
@Cached("createEqualityProfile()") PrimitiveValueProfile lengthProfile) throws ArityException {
if (arguments.length != 3) {
CompilerDirectives.transferToInterpreter();
throw ArityException.create(3, arguments.length);
throw ArityException.create(3, 3, arguments.length);
}
long size;
try {
Expand Down Expand Up @@ -355,7 +355,7 @@ Object execute(Object[] arguments,
@Cached("createEqualityProfile()") PrimitiveValueProfile lengthProfile) throws ArityException {
if (arguments.length != 3) {
CompilerDirectives.transferToInterpreter();
throw ArityException.create(3, arguments.length);
throw ArityException.create(3, 3, arguments.length);
}
int length = lengthProfile.profile(args.length);
Object[] mappedArgs = new Object[length];
Expand Down Expand Up @@ -443,7 +443,7 @@ Object execute(Object[] arguments,
@CachedLibrary(limit = "2") InteropLibrary memberInterop) throws ArityException, UnsupportedTypeException, UnsupportedMessageException {
if (arguments.length != 3) {
CompilerDirectives.transferToInterpreter();
throw ArityException.create(3, arguments.length);
throw ArityException.create(3, 3, arguments.length);
}
Object value = parentInterop.execute(parent, arguments);
try {
Expand Down Expand Up @@ -503,7 +503,7 @@ Object execute(Object[] arguments,
@CachedLibrary(limit = "2") InteropLibrary elementInterop) throws ArityException, UnsupportedTypeException, UnsupportedMessageException {
if (arguments.length != 3) {
CompilerDirectives.transferToInterpreter();
throw ArityException.create(3, arguments.length);
throw ArityException.create(3, 3, arguments.length);
}
Object value = parentInterop.execute(parent, arguments);
try {
Expand Down Expand Up @@ -563,7 +563,7 @@ Object execute(Object[] arguments,
@CachedLibrary("this.function") InteropLibrary mapInterop) throws UnsupportedTypeException, ArityException, UnsupportedMessageException {
if (arguments.length != 3) {
CompilerDirectives.transferToInterpreter();
throw ArityException.create(3, arguments.length);
throw ArityException.create(3, 3, arguments.length);
}
Object value = parentInterop.execute(parent, arguments);
try {
Expand Down Expand Up @@ -639,7 +639,7 @@ Object execute(Object[] arguments,
@CachedLibrary("this.parent") InteropLibrary parentInterop) throws UnsupportedTypeException, ArityException, UnsupportedMessageException {
if (arguments.length != 3) {
CompilerDirectives.transferToInterpreter();
throw ArityException.create(3, arguments.length);
throw ArityException.create(3, 3, arguments.length);
}
return new ShreddedObject(parentInterop.execute(parent, arguments));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,7 @@ public Object call(CUDARuntime cudaRuntime, Object[] args) throws ArityException
}
} else {
CompilerDirectives.transferToInterpreter();
throw ArityException.create(3, args.length);
throw ArityException.create(1, 3, args.length);
}

// Extract pointers;
Expand Down Expand Up @@ -944,7 +944,7 @@ public Object call(CUDARuntime cudaRuntime, Object[] args) throws ArityException
streamObj = args[3];
} else {
CompilerDirectives.transferToInterpreter();
throw ArityException.create(4, args.length);
throw ArityException.create(3, 4, args.length);
}

if (args[1] instanceof Long) {
Expand Down Expand Up @@ -1005,12 +1005,10 @@ public Object call(CUDARuntime cudaRuntime, Object[] args) throws ArityException
public Object call(CUDARuntime cudaRuntime, Object[] args) throws ArityException, UnsupportedTypeException, InteropException {
checkArgumentLength(args, 3);

Object pointerFloat = args[0];
Object pointerStartEvent = args[1];
Object pointerEndEvent = args[2];
long addrStart;
long addrEnd;
long addrFloat;

if (pointerStartEvent instanceof CUDAEvent) {
addrStart = ((CUDAEvent) pointerStartEvent).getRawPointer();
Expand All @@ -1022,12 +1020,10 @@ public Object call(CUDARuntime cudaRuntime, Object[] args) throws ArityException
} else {
throw new GrCUDAException("expected CUDAEvent object");
}

try (UnsafeHelper.Float32Object floatPointer = UnsafeHelper.createFloat32Object()) {
callSymbol(cudaRuntime, floatPointer.getAddress(), addrStart, addrEnd );
return NoneValue.get();
}

}
},
CUDA_EVENTRECORD("cudaEventRecord", "(pointer, pointer): sint32") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ KernelArguments createKernelArguments(Object[] args, InteropLibrary booleanAcces
throws UnsupportedTypeException, ArityException {
if (args.length != kernel.getKernelParameters().length) {
CompilerDirectives.transferToInterpreter();
throw ArityException.create(kernel.getKernelParameters().length, args.length);
throw ArityException.create(kernel.getKernelParameters().length, kernel.getKernelParameters().length, args.length);
}
KernelArguments kernelArgs = new KernelArguments(args, this.kernel.getKernelParameters());
for (int paramIdx = 0; paramIdx < kernel.getKernelParameters().length; paramIdx++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,9 @@ boolean isExecutable() {
public Object execute(Object[] arguments) throws ArityException {
if (arguments.length != 0) {
CompilerDirectives.transferToInterpreter();
throw ArityException.create(0, arguments.length);
// FIXME: the maximum number of arguments is unbound (as each argument is a dimension of a N-dimensional tensor).
// Truffle currently uses -1 to handle an unbound number of arguments;
throw ArityException.create(0, -1, arguments.length);
}
return runtime.cudaGetDevice() == deviceId;
}
Expand All @@ -203,7 +205,7 @@ boolean isExecutable() {
public Object execute(Object[] arguments) throws ArityException {
if (arguments.length != 0) {
CompilerDirectives.transferToInterpreter();
throw ArityException.create(0, arguments.length);
throw ArityException.create(0, 0, arguments.length);
}
runtime.cudaSetDevice(deviceId);
return NoneValue.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,11 +281,9 @@ Object execute(Object[] arguments,
@CachedLibrary(limit = "3") InteropLibrary blockSizeAccess,
@CachedLibrary(limit = "3") InteropLibrary blockSizeElementAccess,
@CachedLibrary(limit = "3") InteropLibrary sharedMemoryAccess) throws UnsupportedTypeException, ArityException {
// FIXME: ArityException allows to specify only 1 arity, and cannot be subclassed! We might
// want to use a custom exception here;
if (arguments.length < 2 || arguments.length > 4) {
CompilerDirectives.transferToInterpreter();
throw ArityException.create(2, arguments.length);
throw ArityException.create(2, 4, arguments.length);
}

Dim3 gridSize = extractDim3(arguments[0], "gridSize", gridSizeAccess, gridSizeElementAccess);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ boolean isExecutable() {
Object execute(Object[] arguments) throws ArityException {
if (arguments.length != 0) {
CompilerDirectives.transferToInterpreter();
throw ArityException.create(0, arguments.length);
throw ArityException.create(0, 0, arguments.length);
}
freeMemory();
return NoneValue.get();
Expand Down

0 comments on commit 920f52c

Please sign in to comment.