arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2409.08729cs.DC
收藏

GPU上修正贝塞尔函数对数的精确计算

Accurate Computation of the Logarithm of Modified Bessel Functions on GPUs

Andreas Plesner, Hans Henrik Brandenborg Sørensen, Søren Hauberg

AI总结:

针对现有修正贝塞尔函数对数计算精度不足、特定输入易失效且GPU实现有限的问题,提出两种对数尺度计算的新算法,实现高精度与大幅加速,可完成高维vMF分布拟合并提供GPU开源实现。

摘要:

贝塞尔函数在科学计算中至关重要,应用于机器学习、蛋白质结构建模和机器人学等领域。然而,现有计算例程要么精度不足,要么在特定输入范围(如阶数$v$较大时)失效,且针对GPU的实现十分有限。我们解决了当前数值实现的精度局限,同时大幅提升了运行速度。我们提出两种新颖算法,通过在对数尺度上计算中间值来求解第一类和第二类修正贝塞尔函数的对数。我们的算法鲁棒性强,绝不会出现下溢或上溢问题,即使在现有函数库失效的输入下,相对误差也处于机器精度量级。在测试的输入范围和第三方库中,基于C++/CUDA实现的我们的算法在GPU上的中位加速比为45倍、最大加速比为6150倍,在CPU上的中位加速比为17倍、最大加速比为3403倍。与SciPy相比,在测试输入下,该算法在GPU上的中位加速比为77倍、最大加速比为300倍,在CPU上的中位加速比为35倍、最大加速比为98倍。\n鲁棒的求解能力和极低的相对误差使我们能够将von Mises-Fisher(vMF,冯·米塞斯-费舍尔)分布拟合到高维神经网络特征中,这一应用例如与度量学习中的不确定性量化相关。我们通过预训练ResNet50的卷积层处理CIFAR10训练图像,得到图像特征数据。利用我们的算法,我们成功将vMF分布拟合到2048维、8192维和32768维的图像特征数据中。我们的方法能得到快速且准确的结果,而SciPy和mpmath中的现有实现无法完成成功拟合。\n我们的方法易于在GPU上实现,且我们随本文提供了一个快速的开源实现。

英文摘要:

Bessel functions are critical in scientific computing for applications such as machine learning, protein structure modeling, and robotics. However, currently, available routines lack precision or fail for certain input ranges, such as when the order $v$ is large, and GPU-specific implementations are limited. We address the precision limitations of current numerical implementations while dramatically improving the runtime. We propose two novel algorithms for computing the logarithm of modified Bessel functions of the first and second kinds by computing intermediate values on a logarithmic scale. Our algorithms are robust and never have issues with underflows or overflows while having relative errors on the order of machine precision, even for inputs where existing libraries fail. In C++/CUDA, our algorithms have median and maximum speedups of 45x and 6150x for GPU and 17x and 3403x for CPU, respectively, over the ranges of inputs and third-party libraries tested. Compared to SciPy, the algorithms have median and maximum speedups of 77x and 300x for GPU and 35x and 98x for CPU, respectively, over the tested inputs. The ability to robustly compute a solution and the low relative errors allow us to fit von Mises-Fisher, vMF, distributions to high-dimensional neural network features. This is, e.g., relevant for uncertainty quantification in metric learning. We obtain image feature data by processing CIFAR10 training images with the convolutional layers of a pre-trained ResNet50. We successfully fit vMF distributions to 2048-, 8192-, and 32768-dimensional image feature data using our algorithms. Our approach provides fast and accurate results while existing implementations in SciPy and mpmath fail to fit successfully. Our approach is readily implementable on GPUs, and we provide a fast open-source implementation alongside this paper.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑