Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function to get the amount of memory used by torch tensors #676

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

fmassa
Copy link
Contributor

@fmassa fmassa commented May 7, 2016

Allows to get the amount of memory used by torch tensors.

In conjunction with collectgarbage('count'), we can have some good estimates of the total amount of memory used (except if other data structures are used, like tds).

Note: as heapSize is only updated by batches of ~ 1MB, so creating really small tensors won't show any immediate difference.

I will add docs if we agree to merge this.

@@ -250,6 +256,7 @@ static const struct luaL_Reg torch_utils__ [] = {
{"pointer", luaT_lua_pointer},
{"setheaptracking", torch_setheaptracking},
{"updateerrorhandlers", torch_updateerrorhandlers},
{"getmemory", torch_getmemory},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about memoryused? It might be more self-explanatory.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that simply getmemory is not a good name.
memoryused is indeed better.
Any other opinions ? cutorch has a getMemoryUsage (which prints the total memory available and the memory used for the GPU). Maybe it would be good to have some uniformity in there.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getMemoryUsage sounds good to me as well 😄 I agree that it might be better to keep it similar.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but there is a difference between getMemoryUsage and this PR in the sense that this PR aims at showing the memory used by torch, and not the total memory used. BTW, the same PR could be done in cutorch, in which case we would have different functions which behave differently but with a similar purpose.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, ok, you're right. Do you have any suggestions for the name? getTorchMemory[Usage]?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

torch.getHeapSize ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds a bit as if it would return Lua's heap size as well, but I like it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

torch.tensormemoryusage_if_youre_not_using_too_many_threads_plusOrMinus100MB()

@fmassa
Copy link
Contributor Author

fmassa commented May 7, 2016

Also, I could add heapDelta to heapSize to have a better estimate of the count of memory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants