在 CUDA/Thrust 中使用固定大小的向量类型

问题描述 投票:0回答:1

我是 CUDA/Thrust 的新手,因此这个问题可能很愚蠢。我想要的是在 GPU 上对固定大小的浮点向量的动态大小数组进行操作。据我所知,CUDA/Thrust 中没有内置的固定大小的浮点向量类型。

所以,我想出了类似的东西

模板 课点 { 民众: 使用 value_type = RealType; 使用参考 = value_type&; 使用 const_reference = value_type const&;

__host__ __device__ __forceinline__
auto constexpr begin() noexcept { return &m_data[0]; }
__host__ __device__ __forceinline__
auto constexpr begin() const noexcept { return &m_data[0]; }
__host__ __device__ __forceinline__
auto constexpr cbegin() const noexcept { return &m_data[0]; }
__host__ __device__ __forceinline__
auto constexpr end() noexcept { return &m_data[D]; }
__host__ __device__ __forceinline__
auto constexpr end() const noexcept { return &m_data[D]; }
__host__ __device__ __forceinline__
auto constexpr cend() const noexcept { return &m_data[D]; }

__host__ __device__ __forceinline__
constexpr reference operator[](std::size_t i) { return m_data[i]; }
__host__ __device__ __forceinline__
constexpr const_reference operator[](std::size_t i) const { return m_data[i]; }

私人: RealType m_data[D]; }; // 类点

现在,我不知道我应该如何定义

operator+
等等。例如,如果我只是做

template<typename RealType, std::size_t D>
__host__ __device__ __forceinline__
point<RealType, D> operator+(point<RealType, D> first, point<RealType, D> const& second) noexcept
{
    for (std::size_t i = 0; i < D; ++i)
        first[i] += second;
    return first;
}

我不会失去任何从 SIMD 指令中获益的机会吗?我可以或应该做什么?


(我不确定在我的应用程序中使用 Eigen::Vector 是否明智,因为我也有应该在 CPU 上运行的代码这可能有问题

cuda c++20 thrust
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.