LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

GPU Accelerate Interpolate 2d Scattered

Hello World,


I'm looking to put about 50k data points through the linear interpolate process of this VI:
https://zone.ni.com/reference/en-XX/help/371361R-01/gmath/interpolate_2d_scattered/

 

It works, barley, but takes much too long for my desired application.

 

I understand from this article, and a friend in CS, that I can use my GPU instead of the CPU to change this into a trivial task:
https://knowledge.ni.com/KnowledgeArticleDetails?id=kA00Z0000015AcdSAE&l=en-US

Before I embark on this journey alone, I wanted to ask if anyone has experience doing this or has already done it before? If so, is there code already out there?

0 Kudos
Message 1 of 10
(1,026 Views)

Just be aware that doing this will lock your code to work only on computers with the same GPU (or at least the same GPU company).

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 2 of 10
(1,001 Views)

@billko wrote:

Just be aware that doing this will lock your code to work only on computers with the same GPU (or at least the same GPU company).


OK, so using the NVIDIA CUDA library for example, will limit the program to only work with NVIDIA GPUs? I can live with that.

Is there a way to programmatically check in LabVIEW if a computer has a compatible GPU?

0 Kudos
Message 3 of 10
(970 Views)

I have installed this Toolkit on windows 10 running LabView 2020 64 bit and Cuda 10.1

 

system-info.png

 

its quite an old NVIDIA Hardware, but still runs the examples the Toolkit ships.

alexderjuengere_0-1631302940487.png

 

 

I once tried to outsource a AxB Matrix operation, which can be done by modifying the shipping examples) using this Toolkit - and yes, the calculation is faster than on CPU .... but:

it took too long to upload and download the data to the gpu - before and after the actual caluclation - for my purposes.

 

 

There was quite a good forum post about this, somewhere in https://forums.ni.com/t5/GPU-Computing/bd-p/5053

 

0 Kudos
Message 4 of 10
(949 Views)

Have you tried speeding up the CPU code to see if you can make it fast enough? Make a copy of the Interpolate 2D Scattered function, and just isolate the code path you're using. I presume because you're talking about the AxB function that you're using the biharmonic spline (Green's Function) interpolation. One thing to try is to parallelize the outer For Loops - depending on your machine, that might give a 5-10x speedup. A second would be to install the Multicore Analysis and Sparse Matrix Toolkit and replace the matrix calls with the corresponding MASM routines - these are typically much faster.

 

The Green's Function interpolation is almost identical to a simple Kriging interpolation, which I tend to use for 2D or 3D interpolation. The code I've written here has a different way of passing the positions where the information is all in one array. Note also that instead of solving the linear equations directly (the Disabled code), a pseudo-inverse/multiply is used, otherwise there can be problems with an Interpolation Position that is exactly at a Data Position (also an issue with the NI routine).

Kriging Interpolation Simple_BD.png

 

Again you can replace parallelize the For loops and change to MASM matrix calls to speed this up further - I've done this in the LV2018 VI attached. One further speedup here is using SGL arrays which MASM supports directly and are typically several times faster than DBL arrays.

 

A big advantage of this method is if you have a set of fixed Data Positions that have changing values. Then you can compute the Weights only once at the start, and just call the AxB matrix function with each new set of Data Values.

Message 5 of 10
(901 Views)

@GregSands wrote:

Have you tried speeding up the CPU code to see if you can make it fast enough? Make a copy of the Interpolate 2D Scattered function, and just isolate the code path you're using. I presume because you're talking about the AxB function that you're using the biharmonic spline (Green's Function) interpolation. One thing to try is to parallelize the outer For Loops - depending on your machine, that might give a 5-10x speedup. A second would be to install the Multicore Analysis and Sparse Matrix Toolkit and replace the matrix calls with the corresponding MASM routines - these are typically much faster.

 

The Green's Function interpolation is almost identical to a simple Kriging interpolation, which I tend to use for 2D or 3D interpolation. The code I've written here has a different way of passing the positions where the information is all in one array. Note also that instead of solving the linear equations directly (the Disabled code), a pseudo-inverse/multiply is used, otherwise there can be problems with an Interpolation Position that is exactly at a Data Position (also an issue with the NI routine).

Kriging Interpolation Simple_BD.png

 

Again you can replace parallelize the For loops and change to MASM matrix calls to speed this up further - I've done this in the LV2018 VI attached. One further speedup here is using SGL arrays which MASM supports directly and are typically several times faster than DBL arrays.

 

A big advantage of this method is if you have a set of fixed Data Positions that have changing values. Then you can compute the Weights only once at the start, and just call the AxB matrix function with each new set of Data Values.


Greg,

Thanks! I'll try this today. To be clear, this is the function I'm trying to replicate:

2D Linear Interp Replicate Target.png

0 Kudos
Message 6 of 10
(881 Views)
0 Kudos
Message 7 of 10
(863 Views)

@alexderjuengere wrote:



2D Linear Interp Replicate Target.png


 

that reminds me of this old post

https://forums.ni.com/t5/LabVIEW/Data-interpolation-inside-a-volume/td-p/2056790?profile.language=en


Maybe, It wouldn't surprise me to learn Altenbach solved my problem multiple years ago. I assume you're talking about this VI?

TrilinearInterpolation.png

 

I see the resemblance, but I'll need some help converting my inputs to his. 

0 Kudos
Message 8 of 10
(858 Views)

I think altenbach's Trilinear Interpolation assumes that the source data is on a grid, so not scattered.

 

In terms of using the Kriging vi, I created this quick demo to show how the VI attached above maps to the Interpolate 2D Scattered data organization.

 

Kriging Demo.png

Message 9 of 10
(849 Views)

@JScherer


could you post  some typicial data?

 

can we work with the demo data in gregs Kriging Demo.vi ‏26 KB ,

3DInterpolation.vi ‏22 KB,

or does your data look different ?

0 Kudos
Message 10 of 10
(786 Views)