Currently the transformation is returning all zeros. Any insight would be greatly appreciated! Thanks.
struct Transformer
{
int3 stride_;
Transformer(int3 stride) : stride_(stride)
{
}
host device
int operator()(const float3 & pt)
{
return (
pt.x +
pt.y * stride_.y +
pt.z * stride_.z
);
}
}
##Main code
thrust::host_vector indices(len);
thrust::device_vector pts(len);
thrust::device_vector d_indices(len);
thrust::copy_n(input, len, pts.begin());
thrust::transform(pts.begin(), pts.end(), d_indices.begin(), Transformer({ 250,250,250 }));
I don’t get all zeroes:
$ cat t23.cu
#include <thrust/device_vector.h>
#include <thrust/host_vector.h>
#include <thrust/copy.h>
#include <thrust/transform.h>
#include <iostream>
struct Transformer
{
int3 stride_;
Transformer(int3 stride) : stride_(stride)
{
}
__host__ __device__
int operator()(const float3 & pt)
{
return (
pt.x +
pt.y * stride_.y +
pt.z * stride_.z
);
}
};
int main(){
float3 input[] = { {10.0f,10.0f,10.0f}};
const int len = sizeof(input)/sizeof(input[0]);
thrust::host_vector<int> indices(len);
thrust::device_vector<float3> pts(len);
thrust::device_vector<int> d_indices(len);
thrust::copy_n(input, len, pts.begin());
thrust::transform(pts.begin(), pts.end(), d_indices.begin(), Transformer({ 250,250,250 }));
thrust::copy_n(d_indices.begin(), len, std::ostream_iterator<int>(std::cout, ","));
std::cout << std::endl;
}
$ nvcc -std=c++11 -o t23 t23.cu
$ ./t23
5010,
$
In the future, if you are asking for help, please provide a complete code, just as I have done.