Files
tinygrad/accel/rawcpu/cbuffer.h
George Hotz 783c120a8c rawcpu (#365)
* rawcpu

* add should work when we respect shapetracker

* now that's true

* still have to handle shapetracker

* copyin

* Fix mypy
2022-08-17 11:33:20 +02:00

27 lines
459 B
C++

class CBuffer {
public:
CBuffer(int size_, void* dat = NULL) {
size = size_;
buf = (float*)malloc(size*4);
}
void copyin(void *dat) {
memcpy(buf, dat, size*4);
}
void add(CBuffer *x, CBuffer *y) {
for (int i = 0; i < size; i++) {
buf[i] = x->buf[i] + y->buf[i];
}
}
void mul(CBuffer *x, CBuffer *y) {
for (int i = 0; i < size; i++) {
buf[i] = x->buf[i] * y->buf[i];
}
}
float *buf;
int size;
};