no read out of bounds

This commit is contained in:
George Hotz
2020-12-31 09:41:36 -05:00
parent 1fb5fcafce
commit de7fe085de
2 changed files with 3 additions and 4 deletions

View File

@@ -112,7 +112,7 @@ Relu, Log, Exp # unary ops
Add, Sub, Mul, Pow # binary ops (with broadcasting)
Sum, Max # reduce ops (with axis argument)
Reshape, Transpose, Slice # movement ops
Matmul, Conv2D # heavy data processing ops
Matmul, Conv2D # processing ops
```
While more ops may be added (like Sign), I think these base 14 are stable.

View File

@@ -311,12 +311,11 @@ def inner_slice(ctx, x, arg):
int zero = 1;
for (int dim = 0; dim < n_dims; dim++) {
prod /= shape_ret[dim];
int tidx = (gid / prod) % shape_ret[dim];
int sidx = tidx + shift[dim];
int sidx = (gid / prod) % shape_ret[dim] + shift[dim];
zero &= (sidx >= 0 && sidx < shape_x[dim]);
iptr = (iptr * shape_x[dim]) + sidx;
}
output[gid] = input[iptr] * zero;
output[gid] = zero ? input[iptr] : 0.0;
}""")
gslice(ctx.cl_queue, [np.prod(ret.shape)], None,
x.cl, ret.cl, i32(np.prod(ret.shape)), i32(len(ret.shape)),