Commit d451ce6d authored by Xuan Thang Nguyen's avatar Xuan Thang Nguyen
Browse files

sort 3D points

parent 10b97b22
Loading
Loading
Loading
Loading
+15 −11
Original line number Diff line number Diff line
@@ -141,26 +141,30 @@ TEST(types, type_double)
    ASSERT_TRUE(view == cudaArr2.getView());
}

struct TMPSTRUCT{
    uint8_t m_data[16];

    __cuda_callable__ TMPSTRUCT(){m_data[0] = 0;}
    __cuda_callable__ TMPSTRUCT(int first){m_data[0] = first;};
    __cuda_callable__ bool operator <(const TMPSTRUCT& other) const { return m_data[0] < other.m_data[0];}
struct TMPSTRUCT_xyz{
    double x, y, z;
    __cuda_callable__ TMPSTRUCT_xyz(): x(0){}
    __cuda_callable__ TMPSTRUCT_xyz(int first){x = first;};
    __cuda_callable__ bool operator <(const TMPSTRUCT_xyz& other) const { return x< other.x;}
    __cuda_callable__ TMPSTRUCT_xyz& operator =(const TMPSTRUCT_xyz& other) {x = other.x; return *this;}
};
std::ostream & operator<<(std::ostream & out, const TMPSTRUCT_xyz & data){return out << data.x;}


TEST(types, struct)
{
    std::srand(8451);
    std::srand(46151);

    int size = (1<<13);
    std::vector<TMPSTRUCT> arr(size);
    for(auto & x : arr) x = TMPSTRUCT(std::rand());
    int size = (1<<18);
    std::vector<TMPSTRUCT_xyz> arr(size);
    for(auto & x : arr) x = TMPSTRUCT_xyz(std::rand());

    TNL::Containers::Array<TMPSTRUCT, TNL::Devices::Cuda> cudaArr(arr);
    TNL::Containers::Array<TMPSTRUCT_xyz, TNL::Devices::Cuda> cudaArr(arr);
    auto view = cudaArr.getView();
    //thrust::sort(thrust::device, cudaArr.getData(), cudaArr.getData() + cudaArr.getSize());
    //std::cout << view << std::endl;
    quicksort(view);
    ASSERT_TRUE(is_sorted(view));
}

//----------------------------------------------------------------------------------