tutorials icon indicating copy to clipboard operation
tutorials copied to clipboard

(Libtorch)How to use packed_accessor64 to access tensor elements in CUDA?

Open tangyipeng100 opened this issue 4 years ago • 4 comments

The tutorial gives an example about using packed_accessor64 to access tensor elements efficiently as follows. However, I still do not know how to use packed_accessor64. Can anyone give me a more specific example? Thanks.

__global__ void packed_accessor_kernel(
    PackedTensorAccessor64<float, 2> foo,
    float* trace) {
  int i=threadIdx.x
  gpuAtomicAdd(trace, foo[i][i])
}
 
torch::Tensor foo = torch::rand({12, 12});
 
// assert foo is 2-dimensional and holds floats.
auto foo_a = foo.packed_accessor64<float,2>();
float trace = 0;
 
packed_accessor_kernel<<<1, 12>>>(foo_a, &trace);

cc @sekyondaMeta @svekars @carljparker @NicolasHug @kit1980 @subramen

tangyipeng100 avatar May 24 '21 15:05 tangyipeng100

/assigntome

Samsonboadi avatar Jun 01 '23 14:06 Samsonboadi

/assigntome

wittyicon29 avatar Jun 03 '23 10:06 wittyicon29

/assigntome

noqqaqq avatar Jun 12 '23 18:06 noqqaqq

/assigntome

tmbrantley avatar Nov 07 '23 00:11 tmbrantley