Skip to content

Commit 703ccbb

Browse files
killeentsoumith
authored andcommitted
Advanced Indexing: Calculate linear offsets directly on the GPU when working with CUDA Tensors
1 parent a207292 commit 703ccbb

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

generic/THTensor.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,8 @@ void THTensor_(expandNd)(THTensor **rets, THTensor **ops, int count) {
321321
THArgCheck(THTensor_(nDimension)(ops[i]) > 0, i, "can't expand empty tensor %d", i);
322322
}
323323

324-
long *op_sizes[count];
325-
long op_dims[count];
324+
long **op_sizes = THAlloc(sizeof(long*) * count);
325+
long *op_dims = THAlloc(sizeof(long) * count);
326326

327327
for (int i = 0; i < count; ++i) {
328328
op_sizes[i] = ops[i]->size;
@@ -339,6 +339,8 @@ void THTensor_(expandNd)(THTensor **rets, THTensor **ops, int count) {
339339
1024);
340340

341341
if(ret != 0) {
342+
THFree(op_sizes);
343+
THFree(op_dims);
342344
THLongStorage_free(sizes);
343345
THError(error_buffer);
344346
return;
@@ -348,6 +350,8 @@ void THTensor_(expandNd)(THTensor **rets, THTensor **ops, int count) {
348350
THTensor_(expand)(rets[i], ops[i], sizes);
349351
}
350352

353+
THFree(op_sizes);
354+
THFree(op_dims);
351355
THLongStorage_free(sizes);
352356
}
353357

0 commit comments

Comments
 (0)