Опитвам се да напиша персонализирана функция за извършване на сума. Проследих този въпрос Cuda Thrust Custom function, за да направя справка. Ето как дефинирах своя функтор
struct hashElem
{
int freq;
int error;
};
//basically this function adds some value to to the error field of each element
struct hashErrorAdd{
const int error;
hashErrorAdd(int _error): error(_error){}
__host__ __device__
struct hashElem operator()(const hashElem& o1,const int& o2)
{
struct hashElem o3;
o3.freq = o1.freq;
o3.error = o1.error + (NUM_OF_HASH_TABLE-o2)*error; //NUM_OF_HASH_TABLE is a constant
return o3;
}
};
struct hashElem freqError[SIZE_OF_HASH_TABLE*NUM_OF_HASH_TABLE];
int count[SIZE_OF_HASH_TABLE*NUM_OF_HASH_TABLE];
thrust::device_ptr<struct hashElem> d_freqError(freqError);
thrust::device_ptr<int> d_count(count);
thrust::transform(thrust::device,d_freqError,d_freqError+new_length,d_count,hashErrorAdd(perThreadLoad)); //new_length is a constant
Този код при компилация дава следната грешка:
грешка: функцията "hashErrorAdd::operator()" не може да бъде извикана с дадения списък с аргументи
типовете аргументи са: (hashElem)
типът на обекта е: hashErrorAdd
Моля, може ли някой да ми обясни защо получавам тази грешка? и как мога да го разреша. Моля, коментирайте, в случай че не мога да обясня ясно проблема. Благодаря ти.