Profile GPU and CPU copying.
Moving memory is slow, and therefor monitoring the time spent converting
and limiting the number of copy operations can improve performance.
@@ -157,6 +157,7 @@ class Tensor:
def cpu(self):
if self.gpu:
+ with ProfileOp("toCPU", [self]):
ret = Tensor(np.empty(self.shape, dtype=np.float32), gpu=False)
cl.enqueue_copy(cl_queue, ret.data, self.data.cl, is_blocking=True)
if self.grad:
@@ -173,6 +174,7 @@ class Tensor:
if not GPU:
raise Exception("No GPU Support, install pyopencl")
if not self.gpu:
+ with ProfileOp("toGPU", [self]):
require_init_gpu()
ret = Tensor(GPUBuffer(self.shape, self.data))
if self.grad:
