任何保证 Torch 不会弄乱已经分配的 CUDA 数组?
Any guarantees that Torch won't mess up with an already allocated CUDA array?
假设我们通过 PyTorch 以外的其他方式在 GPU 上分配了一些数组,例如使用 numba.cuda.device_array
创建 GPU 数组。 PyTorch 在为某些张量分配稍后的 GPU 内存时,是否会不小心覆盖用于我们的第一个 CUDA 数组的内存 space?总的来说,由于 PyTorch 和 Numba 使用相同的 CUDA 运行时,因此我假设使用相同的内存管理机制,它们是否自动意识到其他 CUDA 程序使用的内存区域,或者它们中的每一个都将整个 GPU 内存视为自己的内存?如果是后者,有没有办法让他们知道其他 CUDA 程序的分配?
编辑:认为这将是一个重要的假设:假设所有分配都由同一进程完成。
Will PyTorch, when allocating later GPU memory for some tensors, accidentally overwrite the memory space that is being used for our first CUDA array?
没有
are they automatically aware of memory regions used by other CUDA programs ...
它们不是 "aware",但每个进程都有自己独立的上下文......
... or does each one of them see the entire GPU memory as his own?
... 上下文有自己的地址 spaces 和隔离。所以两者都不是,但是没有内存损坏的风险。
If it's the latter, is there a way to make them aware of allocations by other CUDA programs?
如果 "aware" 是指 "safe",那么它会自动发生。如果 "aware" 你暗示某种互操作性,那么这在某些平台上是可能的,但它不是自动的。
... assume that all allocations are done by the same process.
那是另外一种情况。一般来说,同一个进程意味着共享上下文,共享上下文共享内存space,但所有正常地址space保护规则和设施都适用,因此不存在失去安全的风险。
假设我们通过 PyTorch 以外的其他方式在 GPU 上分配了一些数组,例如使用 numba.cuda.device_array
创建 GPU 数组。 PyTorch 在为某些张量分配稍后的 GPU 内存时,是否会不小心覆盖用于我们的第一个 CUDA 数组的内存 space?总的来说,由于 PyTorch 和 Numba 使用相同的 CUDA 运行时,因此我假设使用相同的内存管理机制,它们是否自动意识到其他 CUDA 程序使用的内存区域,或者它们中的每一个都将整个 GPU 内存视为自己的内存?如果是后者,有没有办法让他们知道其他 CUDA 程序的分配?
编辑:认为这将是一个重要的假设:假设所有分配都由同一进程完成。
Will PyTorch, when allocating later GPU memory for some tensors, accidentally overwrite the memory space that is being used for our first CUDA array?
没有
are they automatically aware of memory regions used by other CUDA programs ...
它们不是 "aware",但每个进程都有自己独立的上下文......
... or does each one of them see the entire GPU memory as his own?
... 上下文有自己的地址 spaces 和隔离。所以两者都不是,但是没有内存损坏的风险。
If it's the latter, is there a way to make them aware of allocations by other CUDA programs?
如果 "aware" 是指 "safe",那么它会自动发生。如果 "aware" 你暗示某种互操作性,那么这在某些平台上是可能的,但它不是自动的。
... assume that all allocations are done by the same process.
那是另外一种情况。一般来说,同一个进程意味着共享上下文,共享上下文共享内存space,但所有正常地址space保护规则和设施都适用,因此不存在失去安全的风险。