beehive-lab / TornadoVM

TornadoVM: A practical and efficient heterogeneous programming framework for managed languages
https://www.tornadovm.org
Apache License 2.0
1.17k stars 110 forks source link

Question: Running on the host only #362

Closed gaoyang-li closed 4 months ago

gaoyang-li commented 5 months ago

Hi, if I want to run the program on the host (CPU) only, can I just write the program like this:

public class Test1 {
    public static void runParallel(VectorInt v){
        for (@Parallel int i = 0; i < v.getLength(); i++){
            v.set(i, 1);
        }
    }

    public static void main(String[] args){
        VectorInt v = new VectorInt(10);
        runParallel(v);
    }
}

Will the program run in parallel without heterogeneous computing (TaskGraph)? Thank you in advance.

jjfumero commented 5 months ago

Hi @gaoyang-li , do you mean running in parallel on the CPU?

That program is valid, and you will run the sequential code on the CPU via the Java runtime. The @Parallel annotation is only applied if you build a Task-Graph and a Tornado Execution Plan to run on an accelerator. You can use a multi-core CPU as an accelerator (E.g., using the Intel OpenCL runtime).

gaoyang-li commented 5 months ago

Hi @gaoyang-li , do you mean running in parallel on the CPU?

That program is valid, and you will run the sequential code on the CPU via the Java runtime. The @Parallel annotation is only applied if you build a Task-Graph and a Tornado Execution Plan to run on an accelerator. You can use a multi-core CPU as an accelerator (E.g., using the Intel OpenCL runtime).

Hi @jjfumero. Thanks for your reply. Does "using the Intel OpenCL runtime" mean make BACKEND=opencl? Does this ensure the whole program running on CPU only?

jjfumero commented 5 months ago

No. make BACKEND=opencl links TornadoVM to use an OpenCL runtime when a Task Graph and Execution plan is present . Otherwise, you will run with the selected JDK using the default Java runtime. Does it make sense?

If you have installed the OpenCL CPU Runtime in your system, you can enable TornadoVM to use that runtime. But again, this only work if you program your application using Task-Graphs and Execution Plans. We design it this way to allow the Java runtime to have a complement for GPU/FPGA/CPU execution for data and task parallelism. For everything else, you will still use the default Java runtime.

gaoyang-li commented 5 months ago

No. make BACKEND=opencl links TornadoVM to use an OpenCL runtime when a Task Graph and Execution plan is present . Otherwise, you will run with the selected JDK using the default Java runtime. Does it make sense?

If you have installed the OpenCL CPU Runtime in your system, you can enable TornadoVM to use that runtime. But again, this only work if you program your application using Task-Graphs and Execution Plans. We design it this way to allow the Java runtime to have a complement for GPU/FPGA/CPU execution for data and task parallelism. For everything else, you will still use the default Java runtime.

               tornado --devices
Number of Tornado drivers: 1
Driver: OpenCL
  Total number of OpenCL devices  : 2
  Tornado device=0:0  (DEFAULT)
    OPENCL --  [NVIDIA CUDA] -- NVIDIA GeForce MX250
        Global Memory Size: 2.0 GB
        Local Memory Size: 48.0 KB
        Workgroup Dimensions: 3
        Total Number of Block Threads: [1024]
        Max WorkGroup Configuration: [1024, 1024, 64]
        Device OpenCL C version: OpenCL C 1.2

  Tornado device=0:1
    OPENCL --  [Intel(R) OpenCL HD Graphics] -- Intel(R) UHD Graphics 620 [0x3ea0]
        Global Memory Size: 6.0 GB
        Local Memory Size: 64.0 KB
        Workgroup Dimensions: 3
        Total Number of Block Threads: [256]
        Max WorkGroup Configuration: [256, 256, 256]
        Device OpenCL C version: OpenCL C 1.2

Currently I have two devices (discrete GPU and iGPU). So I have to install the OpenCL CPU Runtime to add one more device, am I right?

jjfumero commented 5 months ago

Yes, you can install for example, Intel oneAPI: https://www.intel.com/content/www/us/en/developer/tools/oneapi/toolkits.html#base-kit

Or only the OpenCL Runtime for CPUs: https://www.intel.com/content/www/us/en/developer/articles/technical/intel-cpu-runtime-for-opencl-applications-with-sycl-support.html

gaoyang-li commented 5 months ago

Yes, you can install for example, Intel oneAPI: https://www.intel.com/content/www/us/en/developer/tools/oneapi/toolkits.html#base-kit

Or only the OpenCL Runtime for CPUs: https://www.intel.com/content/www/us/en/developer/articles/technical/intel-cpu-runtime-for-opencl-applications-with-sycl-support.html

Thank you! @jjfumero

jjfumero commented 4 months ago

It seems this question was already answer. I will close the issue. Feel free to open new issues if you have more questions.