1

I am using Alea GPU to program on GPU using C# language. In my project, I want to reduce all zero elements in an array on GPU, so I plan to use exclusive sum scan to implement it. The next step is I have to get the last element of my scan results in order to find all non-zero elements in an algorithm. In this step, I don't want to copy all results to host, because it is very expensive, but I fail to find a method to extract the last element without copying all elements(Maybe there's a way I don't know?).

Here's my code on my scan part. d_voxeOccupy is a sprase array on the device. What should I do for getting the last element of d_voxeOccupyScan?

    var op = new Func<int, int, int>((a, b) => { return a + b; });
    Alea.Session session = new Alea.Session(gpu);
    var d_voxeOccupyScan = gpu.Allocate<int>(numVoxels);
    GpuExtension.Scan<int>(session, d_voxeOccupyScan, d_voxeOccupy, 0, op, 0);

===UPDATE===

I made an example to explain this problem clearly.

        static void Main(string[] args)
        {
            int[] arrayA = new int[14]{ 0, 0, 3, 0, 0, 6, 0, 9, 0, 12, 0, 0, 0, 15 };

            var gpu = Gpu.Default;
            var op = new Func<int, int, int>((a, b) => { return a + b; });
            Alea.Session session = new Alea.Session(gpu);
            var d_voxeOccupyScan = gpu.AllocateDevice<int>(14);
            var d_voxeOccupy = gpu.AllocateDevice<int>(arrayA);
            GpuExtension.Scan<int>(session, d_voxeOccupyScan.Ptr, d_voxeOccupy.Ptr, 0, 14,op, 0);

            var result = Gpu.CopyToHost(d_voxeOccupyScan);
            foreach (var item in result)
            {
                Console.WriteLine(item);
            }
            Console.ReadKey();
        }

Run this code, we will get an array, the last element is 45. How to extract the last element from this array rather than copying all elements?

Albert Li
  • 31
  • 5
  • I suspect it doesn't matter: the overhead in completing the calculation and getting the card set up to transfer data back is going to be much greater than the extra time to transfer the rest of the array. But it's an interesting question and ought to be possible. – Rup Mar 30 '20 at 11:13
  • Hi Rup, actually I have set up the grids and threads of the gpu. This question is one step in my program and it's very necessary. Now this problem has been solved temporarily cuz I've changed my programming language into C++ / CUDA, but I wish this issue in C# / Alea can also be solved ASAP. – Albert Li Apr 02 '20 at 14:44

0 Answers0