fynv / ThrustRTC

CUDA tool set for non-C++ languages that provides similar functionality like Thrust, with NVRTC at its core.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Inability to do arithmetic operations for different argument types - bug or feature?

abulenok opened this issue · comments

import ThrustRTC as trtc

darr_in1 = trtc.device_vector_from_list([1 ], 'int32_t')
darr_in2 = trtc.device_vector_from_list([1 ], 'int64_t')
darr_out = trtc.device_vector('int64_t', 1)

trtc.Transform_Binary(darr_in1, darr_in2, darr_out, trtc.Plus())

This code will produce an error

header_of_structs.h(11): error: no instance of function template "Plus::operator()" matches the argument list
            argument types are: (int32_t, int64_t)
            object type is: Plus
          detected during instantiation of "auto _S_780244a76f854dd5::operator()(const _T0 &) [with _T0=size_t]" 
saxpy.cu(13): here

1 error detected in the compilation of "saxpy.cu".

Is it a bug or a feature? :)
Thanks

This is due to that the "Plus" functor uses the same template type for both of its arguments.
I think this is consistent to the behavior of thrust::plus< T >
https://thrust.github.io/doc/structthrust_1_1plus.html

Try:

myadd = trtc.Functor( {}, ['x', 'y'], 
'''
         return x + y;
''')

Thank you, @fynv
I guess, @abulenok, then the answer is: it is a feature :) - let's close the issue

Closing..