com.oracle.truffle.api.library.ExportMessage Java Examples

The following examples show how to use com.oracle.truffle.api.library.ExportMessage. 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: GPUDeviceProperties.java    From grcuda with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@ExportMessage
@TruffleBoundary
Object readMember(String member) throws UnknownIdentifierException {
    if (!isMemberReadable(member)) {
        throw UnknownIdentifierException.create(member);
    }
    Object value = properties.get(member);
    if (value == null) {
        DeviceProperty prop = PROPERTY_SET.getProperty(member);
        value = prop.getValue(deviceId, runtime);
        if (prop.isStaticProperty()) {
            properties.put(member, value);
        }
    }
    return value;
}
 
Example #2
Source File: ShreddedObject.java    From grcuda with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@ExportMessage
@TruffleBoundary
public Object readMember(String member,
                @CachedLibrary("this.delegate") InteropLibrary memberInterop) {
    if (memberInterop.isMemberReadable(delegate, member)) {
        try {
            return memberInterop.readMember(delegate, member);
        } catch (UnsupportedMessageException | UnknownIdentifierException e) {
            CompilerDirectives.transferToInterpreter();
            throw new MapException("cannot read 'readable' member: " + e.getMessage());
        }
    } else {
        if (memberInterop.hasArrayElements(delegate)) {
            return new ShreddedObjectMember(delegate, member);
        } else {
            CompilerDirectives.transferToInterpreter();
            throw new MapException("cannot shred object without size and member");
        }
    }
}
 
Example #3
Source File: Device.java    From grcuda with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@ExportMessage
Object readMember(String memberName,
                @Shared("memberName") @Cached("createIdentityProfile()") ValueProfile memberProfile) throws UnknownIdentifierException {
    if (!isMemberReadable(memberName, memberProfile)) {
        CompilerDirectives.transferToInterpreter();
        throw UnknownIdentifierException.create(memberName);
    }
    if (ID.equals(memberName)) {
        return deviceId;
    }
    if (PROPERTIES.equals(memberName)) {
        return properties;
    }
    if (IS_CURRENT.equals(memberName)) {
        return new IsCurrentFunction(deviceId, runtime);
    }
    if (SET_CURRENT.equals(memberName)) {
        return new SetCurrentFunction(deviceId, runtime);
    }
    CompilerDirectives.transferToInterpreter();
    throw UnknownIdentifierException.create(memberName);
}
 
Example #4
Source File: MultiDimDeviceArray.java    From grcuda with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@ExportMessage
Object readMember(String member,
                @Shared("member") @Cached("createIdentityProfile()") ValueProfile memberProfile) throws UnknownIdentifierException {
    if (!isMemberReadable(member, memberProfile)) {
        CompilerDirectives.transferToInterpreter();
        throw UnknownIdentifierException.create(member);
    }
    if (POINTER.equals(memberProfile.profile(member))) {
        return getPointer();
    }
    if (IS_MEMORY_FREED.equals(memberProfile.profile(member))) {
        return arrayFreed;
    }
    if (FREE.equals(memberProfile.profile(member))) {
        return new MultiDimDeviceArrayFreeFunction();
    }
    CompilerDirectives.transferToInterpreter();
    throw new GrCUDAInternalException("trying to read unknown member '" + member + "'");
}
 
Example #5
Source File: MappedFunction.java    From grcuda with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@ExportMessage
Object execute(Object[] arguments,
                @CachedLibrary("this.parent") InteropLibrary parentInterop,
                @CachedLibrary(limit = "2") InteropLibrary memberInterop) throws ArityException, UnsupportedTypeException, UnsupportedMessageException {
    if (arguments.length != 3) {
        CompilerDirectives.transferToInterpreter();
        throw ArityException.create(3, arguments.length);
    }
    Object value = parentInterop.execute(parent, arguments);
    try {
        return memberInterop.readMember(value, name);
    } catch (UnsupportedMessageException | UnknownIdentifierException e) {
        CompilerDirectives.transferToInterpreter();
        throw new MapException("cannot read member '" + name + "' from argument " + parent);
    }
}
 
Example #6
Source File: MapArgObject.java    From grcuda with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@ExportMessage
@TruffleBoundary
Object execute(Object[] arguments) throws UnsupportedMessageException, UnsupportedTypeException, ArityException {
    if (value instanceof MapArgObjectMember) {
        MapArgObjectMember member = (MapArgObjectMember) value;
        if (MAP.equals(member.name)) {
            checkArity(arguments, 1);
            return new MapArgObject(member.parent).map(arguments[0]);
        } else if (SHRED.equals(member.name)) {
            checkArity(arguments, 0);
            CompilerAsserts.neverPartOfCompilation();
            return new MapArgObject(member.parent).shred();
        } else if (DESCRIBE.equals(member.name)) {
            checkArity(arguments, 0);
            CompilerAsserts.neverPartOfCompilation();
            return new MapArgObject(member.parent).describe();
        } else if (BIND.equals(member.name)) {
            checkArity(arguments, 3);
            return member.parent.bind(arguments[0], arguments[1], arguments[2]);
        }
    }
    CompilerDirectives.transferToInterpreter();
    throw UnsupportedMessageException.create();
}
 
Example #7
Source File: DeviceArray.java    From grcuda with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@ExportMessage
Object readMember(String memberName,
                @Shared("memberName") @Cached("createIdentityProfile()") ValueProfile memberProfile) throws UnknownIdentifierException {
    if (!isMemberReadable(memberName, memberProfile)) {
        CompilerDirectives.transferToInterpreter();
        throw UnknownIdentifierException.create(memberName);
    }
    if (POINTER.equals(memberName)) {
        return getPointer();
    }
    if (COPY_FROM.equals(memberName)) {
        return new DeviceArrayCopyFunction(this, DeviceArrayCopyFunction.CopyDirection.FROM_POINTER);
    }
    if (COPY_TO.equals(memberName)) {
        return new DeviceArrayCopyFunction(this, DeviceArrayCopyFunction.CopyDirection.TO_POINTER);
    }
    if (FREE.equals(memberName)) {
        return new DeviceArrayFreeFunction();
    }
    if (IS_MEMORY_FREED.equals(memberName)) {
        return isMemoryFreed();
    }
    CompilerDirectives.transferToInterpreter();
    throw UnknownIdentifierException.create(memberName);
}
 
Example #8
Source File: HashemLexicalScope.java    From mr-hashemi with Universal Permissive License v1.0 6 votes vote down vote up
@ExportMessage
@TruffleBoundary
Object readMember(String member) throws UnknownIdentifierException {
    if (frame == null) {
        return HashemPooch.SINGLETON;
    }
    FrameSlot slot = slots.get(member);
    if (slot == null) {
        throw UnknownIdentifierException.create(member);
    } else {
        Object value;
        Object info = slot.getInfo();
        if (args != null && info != null) {
            value = args[(Integer) info];
        } else {
            value = frame.getValue(slot);
        }
        return value;
    }
}
 
Example #9
Source File: HashemLexicalScope.java    From mr-hashemi with Universal Permissive License v1.0 6 votes vote down vote up
@ExportMessage
@TruffleBoundary
void writeMember(String member, Object value) throws UnsupportedMessageException, UnknownIdentifierException {
    if (frame == null) {
        throw UnsupportedMessageException.create();
    }
    FrameSlot slot = slots.get(member);
    if (slot == null) {
        throw UnknownIdentifierException.create(member);
    } else {
        Object info = slot.getInfo();
        if (args != null && info != null) {
            args[(Integer) info] = value;
        } else {
            frame.setObject(slot, value);
        }
    }
}
 
Example #10
Source File: DeviceArray.java    From grcuda with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@ExportMessage
Object invokeMember(String memberName,
                Object[] arguments,
                @CachedLibrary("this") InteropLibrary interopRead,
                @CachedLibrary(limit = "1") InteropLibrary interopExecute)
                throws UnsupportedTypeException, ArityException, UnsupportedMessageException, UnknownIdentifierException {
    return interopExecute.execute(interopRead.readMember(this, memberName), arguments);
}
 
Example #11
Source File: HashemLexicalScope.java    From mr-hashemi with Universal Permissive License v1.0 5 votes vote down vote up
@ExportMessage
Object readArrayElement(long index) throws InvalidArrayIndexException {
    if (!isArrayElementReadable(index)) {
        throw InvalidArrayIndexException.create(index);
    }
    return keys[(int) index];
}
 
Example #12
Source File: Device.java    From grcuda with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@SuppressWarnings("static-method")
@ExportMessage
public Object execute(Object[] arguments) throws ArityException {
    if (arguments.length != 0) {
        CompilerDirectives.transferToInterpreter();
        throw ArityException.create(0, arguments.length);
    }
    return runtime.cudaGetDevice() == deviceId;
}
 
Example #13
Source File: MultiDimDeviceArray.java    From grcuda with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@ExportMessage
Object invokeMember(String memberName,
                Object[] arguments,
                @CachedLibrary("this") InteropLibrary interopRead,
                @CachedLibrary(limit = "1") InteropLibrary interopExecute)
                throws UnsupportedTypeException, ArityException, UnsupportedMessageException, UnknownIdentifierException {
    return interopExecute.execute(interopRead.readMember(this, memberName), arguments);
}
 
Example #14
Source File: MultiDimDeviceArray.java    From grcuda with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@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 #15
Source File: MapFunction.java    From grcuda with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
@ExportMessage
@TruffleBoundary
public MappedFunction execute(Object[] arguments) throws ArityException, UnsupportedTypeException {
    if (arguments.length == 0) {
        throw ArityException.create(1, 0);
    }
    Object function = arguments[0];
    if (!INTEROP.isExecutable(function)) {
        throw UnsupportedTypeException.create(arguments, "expecting executable function as first argument");
    }
    String description = null;
    if (arguments.length > 1) {
        Object last = arguments[arguments.length - 1];
        if (INTEROP.isString(last)) {
            try {
                description = INTEROP.asString(last);
            } catch (UnsupportedMessageException e) {
                throw new GrCUDAInternalException("mismatch between isString and asString");
            }
        }
    }
    Object[] values = new Object[arguments.length - 1 - (description == null ? 0 : 1)];
    ArgumentSet argSet = new ArgumentSet();
    ArgumentSet shreddedArgSet = new ArgumentSet();
    ArgumentSet valueSet = new ArgumentSet();

    for (int i = 0; i < values.length; i++) {
        values[i] = bindArgument(arguments[i + 1], argSet, shreddedArgSet, valueSet);
    }
    Object boundReturn = bindArgument(returnValue, argSet, shreddedArgSet, valueSet);
    int[] shreddedIndexes = new int[shreddedArgSet.nameList.size()];
    for (String name : shreddedArgSet.nameList.getKeys()) {
        shreddedIndexes[shreddedArgSet.nameList.get(name)] = argSet.readMember(name);
    }
    Integer returnValueIndex = valueSet.nameList.get("return");
    return new MappedFunction(function, values, shreddedIndexes, valueSet.nameList.size(), boundReturn, returnValueIndex, description);
}
 
Example #16
Source File: ArgumentArray.java    From grcuda with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@ExportMessage
public Object readArrayElement(long index) throws InvalidArrayIndexException {
    if (!isArrayElementReadable(index)) {
        CompilerDirectives.transferToInterpreter();
        throw InvalidArrayIndexException.create(index);
    }
    return values[(int) index];
}
 
Example #17
Source File: DeviceArrayFunction.java    From grcuda with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@ExportMessage
Object readMember(String memberName,
                @Shared("memberName") @Cached("createIdentityProfile()") ValueProfile memberProfile) throws UnknownIdentifierException {
    if (MAP.equals(memberProfile.profile(memberName))) {
        return new MapDeviceArrayFunction(runtime);
    }
    CompilerDirectives.transferToInterpreter();
    throw UnknownIdentifierException.create(memberName);
}
 
Example #18
Source File: GPUDeviceProperties.java    From grcuda with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@ExportMessage
@TruffleBoundary
public Object readArrayElement(long index) throws InvalidArrayIndexException {
    if ((index < 0) || (index >= propertyMap.size())) {
        throw InvalidArrayIndexException.create(index);
    }
    return names[(int) index];
}
 
Example #19
Source File: JsonObject.java    From mr-hashemi with Universal Permissive License v1.0 5 votes vote down vote up
@ExportMessage
final Object readMember(@SuppressWarnings("unused") String member) {
    final Object field = fields.get(member);
    if (field instanceof Map) {
        return new JsonObject((Map) field);
    }
    if (field == null) {
        return HashemPooch.SINGLETON;
    }
    return field;
}
 
Example #20
Source File: MultiDimDeviceArrayView.java    From grcuda with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@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 #21
Source File: DeviceList.java    From grcuda with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@ExportMessage
Object readArrayElement(long index) throws InvalidArrayIndexException {
    if ((index < 0) || (index >= devices.length)) {
        CompilerDirectives.transferToInterpreter();
        throw InvalidArrayIndexException.create(index);
    }
    return devices[(int) index];
}
 
Example #22
Source File: HashemInstrumentTest.java    From mr-hashemi with Universal Permissive License v1.0 5 votes vote down vote up
@ExportMessage
Object readArrayElement(long index) throws InvalidArrayIndexException {
    try {
        return keys[(int) index];
    } catch (IndexOutOfBoundsException e) {
        CompilerDirectives.transferToInterpreter();
        throw InvalidArrayIndexException.create(index);
    }
}
 
Example #23
Source File: DeviceArray.java    From grcuda with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@ExportMessage
Object execute(Object[] arguments) throws ArityException {
    if (arguments.length != 0) {
        CompilerDirectives.transferToInterpreter();
        throw ArityException.create(0, arguments.length);
    }
    freeMemory();
    return NoneValue.get();
}
 
Example #24
Source File: MapFunction.java    From grcuda with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@ExportMessage
@SuppressWarnings("static-method")
boolean isExecutable() {
    return true;
}
 
Example #25
Source File: HashemInstrumentTest.java    From mr-hashemi with Universal Permissive License v1.0 4 votes vote down vote up
@ExportMessage
boolean isArrayElementReadable(long index) {
    return index >= 0 && index < keys.length;
}
 
Example #26
Source File: MappedFunction.java    From grcuda with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@ExportMessage
@SuppressWarnings("static-method")
boolean isExecutable() {
    return true;
}
 
Example #27
Source File: HashemLexicalScope.java    From mr-hashemi with Universal Permissive License v1.0 4 votes vote down vote up
@ExportMessage
boolean isArrayElementReadable(long index) {
    return index >= 0 && index < keys.length;
}
 
Example #28
Source File: HashemInstrumentTest.java    From mr-hashemi with Universal Permissive License v1.0 4 votes vote down vote up
@SuppressWarnings("static-method")
@ExportMessage
boolean hasArrayElements() {
    return true;
}
 
Example #29
Source File: ArgumentArray.java    From grcuda with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@ExportMessage
public boolean isArrayElementModifiable(long index) {
    return isArrayElementReadable(index);
}
 
Example #30
Source File: MapFunctionTest.java    From grcuda with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@ExportMessage
@SuppressWarnings("static-method")
boolean isExecutable() {
    return true;
}