Skip to content

[discussion][cuda] pin_memory() asks for ctx on current device #21081

@ssnl

Description

@ssnl

tensor.pin_memory() always asks for a context on the current device. This means that even if you use torch.device('cuda:1') everywhere in the program, a simple DataLoader(..., pin_memory=True) will create a context on GPU 0.

A little dig into cudaHostAlloc and our THCCachingHostAllocator tells me that:

Therefore, I wonder, instead of always asking for a context on the current device, if tensor.pin_memory() should just grab any CUDA context if exists.

@colesbury pointed out that many other functions also create context on current device. But I think they are not as frequent as this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    module: cudaRelated to torch.cuda, and CUDA support in generalmodule: dataloaderRelated to torch.utils.data.DataLoader and SamplertriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions