09-09-2021 02:17 PM
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?
09-09-2021 06:06 PM
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).
09-10-2021 08:46 AM
@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?
09-10-2021 02:41 PM - edited 09-10-2021 02:48 PM
I have installed this Toolkit on windows 10 running LabView 2020 64 bit and Cuda 10.1
its quite an old NVIDIA Hardware, but still runs the examples the Toolkit ships.
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
09-12-2021 07:23 PM
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).
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.
09-13-2021 10:39 AM
@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).
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:
09-13-2021 04:13 PM - edited 09-13-2021 04:14 PM
that reminds me of this old post
https://forums.ni.com/t5/LabVIEW/Data-interpolation-inside-a-volume/td-p/2056790?profile.language=en
09-13-2021 04:40 PM
@alexderjuengere wrote:
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?
I see the resemblance, but I'll need some help converting my inputs to his.
09-13-2021 07:58 PM
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.
09-14-2021 10:22 AM - edited 09-14-2021 10:24 AM
@JScherer
could you post some typicial data?
can we work with the demo data in gregs Kriging Demo.vi 26 KB ,
or does your data look different ?