I wanted to know if this function I made to find the memory address of the last element in a pytorch tensor works. I run it and it seems fine but a couple of times it returns the “last element” of the tensor and it shows that it is in a later part of memory than the first element, which I get using the .data_ptr() function. The tensor is contiguous and has dimensions (3,1000,1000).
I took in the tensor as an argument and then get the last index of the tensor then call the data_ptr() function. This is my code below:
def get_last_mem(tensor):
last_element = tensor[-1,-1].data_ptr()
return last_element
and this is my output
First Element Memory Address before transform: 136496996679680, Contiguous: True
Last Element Memory Address before transform: 136497008679676