mirror of
https://github.com/tinygrad/tinygrad.git
synced 2026-06-24 02:14:17 +00:00
support torch GPU, only autoinit cuda in the buffer
This commit is contained in:
parent
d8d19ed468
commit
0e6832a8ea
2 changed files with 6 additions and 4 deletions
|
|
@ -1,11 +1,11 @@
|
|||
# pip3 install pycuda
|
||||
import pycuda.driver as cuda
|
||||
import pycuda.autoinit
|
||||
|
||||
import numpy as np
|
||||
|
||||
class CudaBuffer:
|
||||
def __init__(self, shape, hostbuf=None):
|
||||
import pycuda.autoinit
|
||||
|
||||
# TODO: these are generic
|
||||
self.shape = shape
|
||||
self.sz = int(np.prod(shape)*4)
|
||||
|
|
|
|||
|
|
@ -1,15 +1,17 @@
|
|||
import os
|
||||
import torch
|
||||
import numpy as np
|
||||
from ..tensor import Function
|
||||
|
||||
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
||||
class TorchBuffer(torch.Tensor):
|
||||
def custompad(x, padding):
|
||||
return torch.nn.functional.pad(x, [item for sublist in padding[::-1] for item in sublist])
|
||||
@staticmethod
|
||||
def fromCPU(data):
|
||||
return TorchBuffer(torch.from_numpy(data).requires_grad_(False))
|
||||
return TorchBuffer(torch.from_numpy(data).requires_grad_(False)).to(device)
|
||||
def toCPU(x):
|
||||
return x.numpy()
|
||||
return x.cpu().numpy()
|
||||
def getdtype(self):
|
||||
return np.float32
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue