CUDA:在数组中获取最大值及其索引 [英] CUDA: Getting max value and its index in an array

查看:2352
本文介绍了CUDA:在数组中获取最大值及其索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个块,每个块在整数数组的单独部分上执行。作为示例:将一个从阵列[0]到阵列[9]和块二从阵列[10]到阵列[20]。



每个区块的数组最大值的最佳索引是什么?



示例块a [0]到a [10]具有以下值:

5 10 2 3 4 34 56 3 9 10 p>

所以56是索引6处的最大值。



我不能使用共享内存,因为数组的大小可能非常大。因此它不适合。有没有任何库允许我这么快?



我知道减少算法,但我认为我的情况是不同的,因为我想得到的索引最大的元素。

解决方案

这不会对原始海报有好处,但对于那些谁来到这个网页寻找答案,我会第二推荐使用已经有一个函数thrust :: max_element的thrust,返回最大元素的索引。还提供了min_element和minmax_element函数。有关详情,请参阅推荐文档此处


I have several blocks were each block executes on separate part of an integer array. As an example: block one from array[0] to array[9] and block two from array[10] to array[20].

What is the best way i can get the index of the max value of the array for each block?

Example block one a[0] to a[10] have the following values:
5 10 2 3 4 34 56 3 9 10

So 56 is the largest value at index 6.

I cannot use the shared memory because the size of the array may be very big. Therefore it won't fit. Are there any libraries that allows me to do so fast?

I know about the reduction algorithm, but i think my case is different because i want to get the index of the largest element.

解决方案

This will not benefit the original poster but for those who came to this page looking for an answer I would second the recommendation to use thrust that already has a function thrust::max_element that does exactly that - returns an index of the largest element. min_element and minmax_element functions are also provided. See thrust documentation for details here.

这篇关于CUDA:在数组中获取最大值及其索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆