Syncleus / aparapi

The New Official Aparapi: a framework for executing native Java and Scala code on the GPU.
http://aparapi.com
Apache License 2.0
466 stars 59 forks source link

[PATCH] Add support for Local arguments in kernel functions #79

Closed CoreRasurae closed 6 years ago

CoreRasurae commented 6 years ago

The patches attached enable support for func(@Local int[] arg1, float arg2,...) or func(int[] arg1_$local$, float arg2, ...).

As the following kernel code illustrates:

   public class LocalSimpleKernelTest extends Kernel {
    private static final int LENGTH = 10;

    public LocalSimpleKernelTest(final AtomicInteger[] max) {
        myArray = new int[LENGTH];
    }

    @Local
    private int myArray[];

    public void doIt1(int baseValue, @Local int arr[]) {
        for (int i = 0; i < LENGTH; i++) {
            arr[i] += baseValue;
        }
    }

    public void doIt2(int baseValue, int arr_$local$[]) {
        for (int i = 0; i < LENGTH; i++) {
            arr_$local$[i] *= baseValue;
        }
    }

    @Override
    public void run() {
        int base = 10;
        doIt1(base, myArray);
        doIt2(2, myArray);
    }

   }

LocalAnnontationsSupport.patch.txt

freemo commented 6 years ago

@CoreRasurae Thank you, can you submit this as a pull request, it will help us streamline testing it and getting it into the next release (i should be doing that in the next few days). Thanks for the submission.

CoreRasurae commented 6 years ago

@freemo Sure, I can do that, but won't be able to do it today. I am also preparing another patch to add support for increased atomics support by allowing AtomicInteger[] arrays to be mapped as OpenCL integers, thus easily allowing atomic operation both on Java and on OpenCL, in case there is interest for this feature. This would allow all supported OpenCL atomic operations on integers.

freemo commented 6 years ago

@CoreRasurae Awesome, yea I'll be happy to add that feature as well as long as there arent any negative impact on existing features (cant imagine there would be). So happy to approve both features, thanks so much.

freemo commented 6 years ago

@CoreRasurae merged your PR, Thanks!