com.oracle.truffle.api.TruffleLanguage.Env Java Examples

The following examples show how to use com.oracle.truffle.api.TruffleLanguage.Env. 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: HashemParseInContextTest.java    From mr-hashemi with Universal Permissive License v1.0 6 votes vote down vote up
@Override
protected CallTarget parse(ParsingRequest request) throws Exception {
    return Truffle.getRuntime().createCallTarget(new RootNode(this) {

        @CompilationFinal private ContextReference<Env> reference;

        @Override
        public Object execute(VirtualFrame frame) {
            return parseAndEval();
        }

        @TruffleBoundary
        private Object parseAndEval() {
            if (reference == null) {
                CompilerDirectives.transferToInterpreterAndInvalidate();
                this.reference = lookupContextReference(EvalLang.class);
            }
            Source aPlusB = Source.newBuilder("hashemi", "a + b", "plus.hashem").build();
            return reference.get().parsePublic(aPlusB, "a", "b").call(30, 12);
        }
    });
}
 
Example #2
Source File: CUDARuntime.java    From grcuda with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public CUDARuntime(GrCUDAContext context, Env env) {
    this.context = context;
    try {
        TruffleObject libcudart = (TruffleObject) env.parseInternal(
                        Source.newBuilder("nfi", "load " + "lib" + CUDA_RUNTIME_LIBRARY_NAME + ".so", "cudaruntime").build()).call();
        TruffleObject libcuda = (TruffleObject) env.parseInternal(
                        Source.newBuilder("nfi", "load " + "lib" + CUDA_LIBRARY_NAME + ".so", "cuda").build()).call();
        TruffleObject libnvrtc = (TruffleObject) env.parseInternal(
                        Source.newBuilder("nfi", "load " + "lib" + NVRTC_LIBRARY_NAME + ".so", "nvrtc").build()).call();
        loadedLibraries.put(CUDA_RUNTIME_LIBRARY_NAME, libcudart);
        loadedLibraries.put(CUDA_LIBRARY_NAME, libcuda);
        loadedLibraries.put(NVRTC_LIBRARY_NAME, libnvrtc);
    } catch (UnsatisfiedLinkError e) {
        throw new GrCUDAException(e.getMessage());
    }

    nvrtc = new NVRuntimeCompiler(this);
    context.addDisposable(this::shutdown);
}
 
Example #3
Source File: HashemContext.java    From mr-hashemi with Universal Permissive License v1.0 5 votes vote down vote up
public HashemContext(HashemLanguage language, TruffleLanguage.Env env, List<NodeFactory<? extends HashemBuiltinNode>> externalBuiltins) {
    this.env = env;
    this.input = new BufferedReader(new InputStreamReader(env.in()));
    this.output = new PrintWriter(env.out(), true);
    this.language = language;
    this.allocationReporter = env.lookup(AllocationReporter.class);
    this.functionRegistry = new HashemBebinRegistry(language);
    this.topScopes = Collections.singleton(Scope.newBuilder("global", functionRegistry.getFunctionsObject()).build());
    installBuiltins();
    for (NodeFactory<? extends HashemBuiltinNode> builtin : externalBuiltins) {
        installBuiltin(builtin);
    }
    this.emptyShape = LAYOUT.createShape(HashemObjectType.SINGLETON);
}
 
Example #4
Source File: GrCUDAContext.java    From grcuda with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public GrCUDAContext(Env env) {
    this.env = env;
    this.cudaRuntime = new CUDARuntime(this, env);

    Namespace namespace = new Namespace(ROOT_NAMESPACE);
    namespace.addNamespace(namespace);
    namespace.addFunction(new BindFunction());
    namespace.addFunction(new BindAllFunction(this));
    namespace.addFunction(new DeviceArrayFunction(cudaRuntime));
    namespace.addFunction(new MapFunction());
    namespace.addFunction(new ShredFunction());
    namespace.addFunction(new BindKernelFunction(cudaRuntime));
    namespace.addFunction(new BuildKernelFunction(cudaRuntime));
    namespace.addFunction(new GetDevicesFunction(cudaRuntime));
    namespace.addFunction(new GetDeviceFunction(cudaRuntime));
    cudaRuntime.registerCUDAFunctions(namespace);
    if (this.getOption(GrCUDAOptions.CuMLEnabled)) {
        Namespace ml = new Namespace(CUMLRegistry.NAMESPACE);
        namespace.addNamespace(ml);
        new CUMLRegistry(this).registerCUMLFunctions(ml);
    }
    if (this.getOption(GrCUDAOptions.CuBLASEnabled)) {
        Namespace blas = new Namespace(CUBLASRegistry.NAMESPACE);
        namespace.addNamespace(blas);
        new CUBLASRegistry(this).registerCUBLASFunctions(blas);
    }
    if (this.getOption(GrCUDAOptions.TensorRTEnabled)) {
        Namespace trt = new Namespace(TensorRTRegistry.NAMESPACE);
        namespace.addNamespace(trt);
        new TensorRTRegistry(this).registerTensorRTFunctions(trt);
    }
    this.rootNamespace = namespace;
}
 
Example #5
Source File: PolyglotPlugin.java    From trufflesqueak with MIT License 5 votes vote down vote up
@TruffleBoundary
private static String findLanguageByMimeType(final Env env, final String mimeType) {
    final Map<String, LanguageInfo> languages = env.getPublicLanguages();
    for (final String registeredMimeType : languages.keySet()) {
        if (mimeType.equals(registeredMimeType)) {
            return languages.get(registeredMimeType).getId();
        }
    }
    return null;
}
 
Example #6
Source File: SqueakOptions.java    From trufflesqueak with MIT License 5 votes vote down vote up
public SqueakContextOptions(final Env env) {
    final OptionValues options = env.getOptions();
    imagePath = options.get(ImagePath);
    imageArguments = options.get(ImageArguments).isEmpty() ? new String[0] : options.get(ImageArguments).split(",");
    isHeadless = options.get(Headless);
    isQuiet = options.get(Quiet);
    disableInterruptHandler = options.get(Interrupts);
    disableStartup = options.get(Startup);
    signalInputSemaphore = options.get(SignalInputSemaphore);
    enableStackDepthProtection = options.get(StackDepthProtection);
    enableStorageStrategies = options.get(StorageStrategies);
    isTesting = options.get(Testing);
}
 
Example #7
Source File: HashemContext.java    From mr-hashemi with Universal Permissive License v1.0 4 votes vote down vote up
/**
 * Return the current Truffle environment.
 */
public Env getEnv() {
    return env;
}
 
Example #8
Source File: HashemParseInContextTest.java    From mr-hashemi with Universal Permissive License v1.0 4 votes vote down vote up
@Override
protected Env createContext(Env env) {
    return env;
}
 
Example #9
Source File: GrCUDAContext.java    From grcuda with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public Env getEnv() {
    return env;
}
 
Example #10
Source File: UnixOSProcessPlugin.java    From trufflesqueak with MIT License 4 votes vote down vote up
@TruffleBoundary
private static String systemGetEnv(final Env env, final String key) {
    return env.getEnvironment().get(key);
}