3 ms·
Let's assume I have an array of 10.000 lat/lng-pairs. I want to compute the length of the track. I duplicate the array and remove the first item in the duplicat
by qwertox 3y ago
Let's assume I have an array of 10.000 lat/lng-pairs. I want to compute the length of the track. I duplicate the array and remove the first item in the duplicated array, append the last entry of the original array to the duplicate in order for them to be equal in length.
Then I use a vectorized haversine algorithm on these arrays to obtain a third one with the distances between each "row" of the two arrays.
With NumPy this is fast, but I guess that a GPU could also perform this and likely do it much faster. Would it be worth it if one has to consider that the data needs to be moved to the GPU and the result be retrieved?
- rational_indian 3y agoYou need to try it and see if it is any faster. NVIDIA has a drop-in replacement for numpy: https://developer.nvidia.com/cunumeric https://developer.nvidia.com/cunumeric.
- dataflow 3y agoNot the answer to your question, but: > I duplicate the array and remove the first item in the duplicated array, append the last entry of the original array to the duplicate in order for them to be equal in length. I assume/hope this is only what you're doing logically, not physically? Otherwise you might as well just compute the length using n - 1 points from the existing array, then do the remaining portion manually and add it to the existing sum. That would avoid the copying of the whole array.
- dist-epoch 3y ago> Would it be worth it if one has to consider that the data needs to be moved to the GPU and the result be retrieved Depends on your batch size. If the computation on the CPU is less than lets say 200 ms it's probably not worth it. Also consider that integrated GPUs don't have separate memory, I'm not sure, but they might not have a high cost of moving data to memory.
- tlb 3y agoProbably not. The computation is only a few trig instructions per array element, so most of the time is moving data on either CPU or GPU.
- kylebarron 3y ago10,000 coordinates are certainly not enough to see the difference, but at some scale this would be faster on the GPU. This is implemented in an nvidia geospatial library call cuspatial: https://docs.rapids.ai/api/cuspatial/legacy/api_docs/spatial/#cuspatial.haversine_distance https://docs.rapids.ai/api/cuspatial/legacy/api_docs/spatial...