Java Code Examples for com.oracle.truffle.api.interop.InvalidArrayIndexException#create()
The following examples show how to use
com.oracle.truffle.api.interop.InvalidArrayIndexException#create() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DeviceList.java From grcuda with BSD 3-Clause "New" or "Revised" License | 5 votes |
@ExportMessage Object readArrayElement(long index) throws InvalidArrayIndexException { if ((index < 0) || (index >= devices.length)) { CompilerDirectives.transferToInterpreter(); throw InvalidArrayIndexException.create(index); } return devices[(int) index]; }
Example 2
Source File: InteropArray.java From trufflesqueak with MIT License | 5 votes |
@ExportMessage protected Object readArrayElement(final long index) throws InvalidArrayIndexException { if (!isArrayElementReadable(index)) { throw InvalidArrayIndexException.create(index); } return keys[(int) index]; }
Example 3
Source File: CompiledCodeObject.java From trufflesqueak with MIT License | 5 votes |
@ExportMessage protected final void writeArrayElement(final long index, final Object value, @Exclusive @Cached final WrapToSqueakNode wrapNode) throws InvalidArrayIndexException { if (isArrayElementReadable(index)) { literals[(int) index] = wrapNode.executeWrap(value); } else { throw InvalidArrayIndexException.create(index); } }
Example 4
Source File: CompiledCodeObject.java From trufflesqueak with MIT License | 5 votes |
@ExportMessage protected final Object readArrayElement(final long index) throws InvalidArrayIndexException { if (isArrayElementReadable(index)) { return literals[(int) index]; } else { throw InvalidArrayIndexException.create(index); } }
Example 5
Source File: ArrayObject.java From trufflesqueak with MIT License | 5 votes |
@ExportMessage protected void writeArrayElement(final long index, final Object value, @Exclusive @Cached final WrapToSqueakNode wrapNode, @Cached final ArrayObjectWriteNode writeNode) throws InvalidArrayIndexException { try { writeNode.execute(this, index, wrapNode.executeWrap(value)); } catch (final ArrayIndexOutOfBoundsException e) { throw InvalidArrayIndexException.create(index); } }
Example 6
Source File: TensorRTRegistry.java From grcuda with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override protected Object call(Object[] arguments) throws ArityException, UnsupportedTypeException, UnsupportedMessageException { checkArgumentLength(arguments, 3); int engineHandle = expectInt(arguments[0]); int batchSize = expectInt(arguments[1]); // extract pointers from buffers array argument Object bufferArg = arguments[2]; if (!INTEROP.hasArrayElements(bufferArg)) { throw UnsupportedMessageException.create(); } int numBuffers = (int) INTEROP.getArraySize(bufferArg); try (UnsafeHelper.PointerArray pointerArray = UnsafeHelper.createPointerArray(numBuffers)) { if (nfiFunction == null) { // load function symbol lazily CompilerDirectives.transferToInterpreterAndInvalidate(); nfiFunction = factory.makeFunction(context.getCUDARuntime(), libraryPath, DEFAULT_LIBRARY_HINT); } for (int i = 0; i < numBuffers; ++i) { try { Object buffer = INTEROP.readArrayElement(bufferArg, i); if (!(buffer instanceof DeviceArray) && !(buffer instanceof GPUPointer)) { UnsupportedTypeException.create(new Object[]{buffer}); } pointerArray.setValueAt(i, INTEROP.asPointer(buffer)); } catch (InvalidArrayIndexException e) { InvalidArrayIndexException.create(i); } } long stream = 0; long eventConsumed = 0; Object result = INTEROP.execute(nfiFunction, engineHandle, batchSize, pointerArray.getAddress(), stream, eventConsumed); if (!INTEROP.fitsInInt(result)) { CompilerDirectives.transferToInterpreter(); throw new RuntimeException("result of 'enqueue' is not an int"); } return INTEROP.asInt(result) == 1; } }
Example 7
Source File: ArgumentArray.java From grcuda with BSD 3-Clause "New" or "Revised" License | 5 votes |
@ExportMessage public void writeArrayElement(long index, Object value) throws InvalidArrayIndexException { if (!isArrayElementReadable(index)) { CompilerDirectives.transferToInterpreter(); throw InvalidArrayIndexException.create(index); } values[(int) index] = value; }
Example 8
Source File: ArgumentArray.java From grcuda with BSD 3-Clause "New" or "Revised" License | 5 votes |
@ExportMessage public Object readArrayElement(long index) throws InvalidArrayIndexException { if (!isArrayElementReadable(index)) { CompilerDirectives.transferToInterpreter(); throw InvalidArrayIndexException.create(index); } return values[(int) index]; }
Example 9
Source File: MultiDimDeviceArrayView.java From grcuda with BSD 3-Clause "New" or "Revised" License | 5 votes |
@ExportMessage Object readArrayElement(long index, @Shared("elementType") @Cached("createIdentityProfile()") ValueProfile elementTypeProfile) throws InvalidArrayIndexException { if ((index < 0) || (index >= mdDeviceArray.getElementsInDimension(thisDimension))) { CompilerDirectives.transferToInterpreter(); throw InvalidArrayIndexException.create(index); } if ((thisDimension + 1) == mdDeviceArray.getNumberDimensions()) { long flatIndex = offset + index * stride; switch (elementTypeProfile.profile(mdDeviceArray.getElementType())) { case CHAR: return mdDeviceArray.getNativeView().getByte(flatIndex); case SINT16: return mdDeviceArray.getNativeView().getShort(flatIndex); case SINT32: return mdDeviceArray.getNativeView().getInt(flatIndex); case SINT64: return mdDeviceArray.getNativeView().getLong(flatIndex); case FLOAT: return mdDeviceArray.getNativeView().getFloat(flatIndex); case DOUBLE: return mdDeviceArray.getNativeView().getDouble(flatIndex); } return null; } else { long off = offset + index * stride; long newStride = mdDeviceArray.getStrideInDimension(thisDimension + 1); return new MultiDimDeviceArrayView(mdDeviceArray, thisDimension + 1, off, newStride); } }
Example 10
Source File: HashemLexicalScope.java From mr-hashemi with Universal Permissive License v1.0 | 5 votes |
@ExportMessage Object readArrayElement(long index) throws InvalidArrayIndexException { if (!isArrayElementReadable(index)) { throw InvalidArrayIndexException.create(index); } return keys[(int) index]; }
Example 11
Source File: GPUDeviceProperties.java From grcuda with BSD 3-Clause "New" or "Revised" License | 5 votes |
@ExportMessage @TruffleBoundary public Object readArrayElement(long index) throws InvalidArrayIndexException { if ((index < 0) || (index >= propertyMap.size())) { throw InvalidArrayIndexException.create(index); } return names[(int) index]; }
Example 12
Source File: MultiDimDeviceArray.java From grcuda with BSD 3-Clause "New" or "Revised" License | 5 votes |
@ExportMessage Object readArrayElement(long index) throws InvalidArrayIndexException { if ((index < 0) || (index >= elementsPerDimension[0])) { CompilerDirectives.transferToInterpreter(); throw InvalidArrayIndexException.create(index); } long offset = index * stridePerDimension[0]; return new MultiDimDeviceArrayView(this, 1, offset, stridePerDimension[1]); }
Example 13
Source File: DeviceArray.java From grcuda with BSD 3-Clause "New" or "Revised" License | 5 votes |
@ExportMessage public void writeArrayElement(long index, Object value, @CachedLibrary(limit = "3") InteropLibrary valueLibrary, @Shared("elementType") @Cached("createIdentityProfile()") ValueProfile elementTypeProfile) throws UnsupportedTypeException, InvalidArrayIndexException { if (arrayFreed) { CompilerDirectives.transferToInterpreter(); throw new GrCUDAException(ACCESSED_FREED_MEMORY_MESSAGE); } if ((index < 0) || (index >= numElements)) { CompilerDirectives.transferToInterpreter(); throw InvalidArrayIndexException.create(index); } try { switch (elementTypeProfile.profile(elementType)) { case CHAR: nativeView.setByte(index, valueLibrary.asByte(value)); break; case SINT16: nativeView.setShort(index, valueLibrary.asShort(value)); break; case SINT32: nativeView.setInt(index, valueLibrary.asInt(value)); break; case SINT64: nativeView.setLong(index, valueLibrary.asLong(value)); break; case FLOAT: // going via "double" to allow floats to be initialized with doubles nativeView.setFloat(index, (float) valueLibrary.asDouble(value)); break; case DOUBLE: nativeView.setDouble(index, valueLibrary.asDouble(value)); break; } } catch (UnsupportedMessageException e) { CompilerDirectives.transferToInterpreter(); throw UnsupportedTypeException.create(new Object[]{value}, "value cannot be coerced to " + elementType); } }
Example 14
Source File: DeviceArray.java From grcuda with BSD 3-Clause "New" or "Revised" License | 5 votes |
@ExportMessage Object readArrayElement(long index, @Shared("elementType") @Cached("createIdentityProfile()") ValueProfile elementTypeProfile) throws InvalidArrayIndexException { if (arrayFreed) { CompilerDirectives.transferToInterpreter(); throw new GrCUDAException(ACCESSED_FREED_MEMORY_MESSAGE); } if ((index < 0) || (index >= numElements)) { CompilerDirectives.transferToInterpreter(); throw InvalidArrayIndexException.create(index); } switch (elementTypeProfile.profile(elementType)) { case CHAR: return nativeView.getByte(index); case SINT16: return nativeView.getShort(index); case SINT32: return nativeView.getInt(index); case SINT64: return nativeView.getLong(index); case FLOAT: return nativeView.getFloat(index); case DOUBLE: return nativeView.getDouble(index); } return null; }
Example 15
Source File: DeviceArray.java From grcuda with BSD 3-Clause "New" or "Revised" License | 5 votes |
@ExportMessage public Object readArrayElement(long index) throws InvalidArrayIndexException { if ((index < 0) || (index >= values.length)) { CompilerDirectives.transferToInterpreter(); throw InvalidArrayIndexException.create(index); } return values[(int) index]; }
Example 16
Source File: HashemInstrumentTest.java From mr-hashemi with Universal Permissive License v1.0 | 5 votes |
@ExportMessage Object readArrayElement(long index) throws InvalidArrayIndexException { try { return keys[(int) index]; } catch (IndexOutOfBoundsException e) { CompilerDirectives.transferToInterpreter(); throw InvalidArrayIndexException.create(index); } }
Example 17
Source File: HashemObjectType.java From mr-hashemi with Universal Permissive License v1.0 | 5 votes |
@ExportMessage Object readArrayElement(long index) throws InvalidArrayIndexException { if (!isArrayElementReadable(index)) { throw InvalidArrayIndexException.create(index); } return keys[(int) index]; }
Example 18
Source File: FunctionsObject.java From mr-hashemi with Universal Permissive License v1.0 | 5 votes |
@ExportMessage Object readArrayElement(long index) throws InvalidArrayIndexException { if (!isArrayElementReadable(index)) { CompilerDirectives.transferToInterpreter(); throw InvalidArrayIndexException.create(index); } return names[(int) index]; }
Example 19
Source File: MultiDimDeviceArrayView.java From grcuda with BSD 3-Clause "New" or "Revised" License | 4 votes |
@ExportMessage void writeArrayElement(long index, Object value, @CachedLibrary(limit = "3") InteropLibrary valueLibrary, @Shared("elementType") @Cached("createIdentityProfile()") ValueProfile elementTypeProfile) throws UnsupportedTypeException, InvalidArrayIndexException { if ((index < 0) || (index >= mdDeviceArray.getElementsInDimension(thisDimension))) { CompilerDirectives.transferToInterpreter(); throw InvalidArrayIndexException.create(index); } if ((thisDimension + 1) == mdDeviceArray.getNumberDimensions()) { long flatIndex = offset + index * stride; try { switch (elementTypeProfile.profile(mdDeviceArray.getElementType())) { case CHAR: mdDeviceArray.getNativeView().setByte(flatIndex, valueLibrary.asByte(value)); break; case SINT16: mdDeviceArray.getNativeView().setShort(flatIndex, valueLibrary.asShort(value)); break; case SINT32: mdDeviceArray.getNativeView().setInt(flatIndex, valueLibrary.asInt(value)); break; case SINT64: mdDeviceArray.getNativeView().setLong(flatIndex, valueLibrary.asLong(value)); break; case FLOAT: // InteropLibrary does not downcast Double to Float due loss of precision mdDeviceArray.getNativeView().setFloat(flatIndex, (float) valueLibrary.asDouble(value)); break; case DOUBLE: mdDeviceArray.getNativeView().setDouble(flatIndex, valueLibrary.asDouble(value)); break; } } catch (UnsupportedMessageException e) { CompilerDirectives.transferToInterpreter(); throw UnsupportedTypeException.create(new Object[]{value}, "value cannot be coerced to " + mdDeviceArray.getElementType()); } } else { CompilerDirectives.transferToInterpreter(); throw new IllegalStateException("tried to write non-last dimension in MultiDimDeviceArrayView"); } }