簡體   English   中英

Cuda推力:: device_vector從特定范圍獲取指針

[英]Cuda thrust::device_vector get pointer from specific range

我有一個向量向量:

thrust::device_vector weights_;

這是連續的內存量,其中每w個項代表一個向量。

在我的函數之一中,我將范圍的開始和結束作為參數傳遞,如下所示:

 __host__ ann::d_vector ann::prop_layer (
                                           unsigned int weights_begin,
                                           unsigned int weights_end,
                                           ann::d_vector & input
                                        ) const

然后,我將其復制到該范圍的新向量中,然后獲得可以在內核中使用的原始指針:

thrust::device_vector<float> weights ( weights_.begin() + weights_begin,
                                       weights_.begin() + weights_end );

float * weight_ptr = thrust::raw_pointer_cast( weights.data() );

some_kernel<<<numBlocks,numThreads>>>( weight_ptr, weight.size() );
  1. 我可以從該范圍獲得指針,而無需先將其復制到新的向量嗎? 這似乎是對copy-realloc的浪費。
  2. 如果無法從該范圍獲得指針,是否可以至少在不復制實際值的情況下將向量分配給該范圍?

我可以從該范圍獲得指針,而無需先將其復制到新的向量嗎? 這似乎是對copy-realloc的浪費。

是的,您可以找到該范圍的指針。

float * weight_ptr = thrust::raw_pointer_cast( weights_.data() ) + weights_begin;

如果無法從該范圍獲得指針,是否可以至少在不復制實際值的情況下將向量分配給該范圍?

不可以,推力矢量不能在現有數據的“頂部”實例化。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM