Skip to content

Commit aa1d2e8

Browse files
committed
Easy feedback fixes applied.
1 parent 6d9e62d commit aa1d2e8

File tree

1 file changed

+17
-22
lines changed

1 file changed

+17
-22
lines changed

src/gpuarray_reduction.c

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,6 @@ struct GpuReductionAttr{
248248
struct GpuReduction{
249249
/* Function Arguments. */
250250
GpuReductionAttr grAttr;
251-
gpucontext* gpuCtx;
252-
ga_reduce_op op;
253251
int nds;
254252
int ndd;
255253
int ndr;
@@ -651,6 +649,8 @@ GPUARRAY_PUBLIC void GpuReductionAttr_free (GpuReductionAttr*
651649
}
652650
GPUARRAY_PUBLIC int GpuReduction_new (GpuReduction** gr,
653651
const GpuReductionAttr* grAttr){
652+
GpuReduction* grOut = NULL;
653+
654654
if (!gr){
655655
return GA_INVALID_ERROR;
656656
}
@@ -659,16 +659,14 @@ GPUARRAY_PUBLIC int GpuReduction_new (GpuReduction**
659659
return GA_INVALID_ERROR;
660660
}
661661

662-
*gr = calloc(1, sizeof(**gr));
663-
if (*gr){
664-
(*gr)->grAttr = *grAttr;
665-
(*gr)->gpuCtx = grAttr->gpuCtx;
666-
(*gr)->op = grAttr->op;
667-
(*gr)->nds = (int)grAttr->maxSrcDims;
668-
(*gr)->ndd = (int)grAttr->maxDstDims;
669-
(*gr)->ndr = (int)(grAttr->maxSrcDims-grAttr->maxDstDims);
662+
grOut = calloc(1, sizeof(*grOut));
663+
if (grOut){
664+
grOut->grAttr = *grAttr;
665+
grOut->nds = (int)grAttr->maxSrcDims;
666+
grOut->ndd = (int)grAttr->maxDstDims;
667+
grOut->ndr = (int)(grAttr->maxSrcDims - grAttr->maxDstDims);
670668

671-
return reduxGenInit(*gr);
669+
return reduxGenInit(grOut);
672670
}else{
673671
return GA_MEMORY_ERROR;
674672
}
@@ -683,7 +681,8 @@ GPUARRAY_PUBLIC int GpuReduction_call (const GpuReduction*
683681
unsigned reduxLen,
684682
const int* reduxList,
685683
int flags){
686-
redux_ctx ctxSTACK, *ctx = &ctxSTACK;
684+
redux_ctx ctxSTACK;
685+
redux_ctx *ctx = &ctxSTACK;
687686
memset(ctx, 0, sizeof(*ctx));
688687

689688
ctx->gr = gr;
@@ -712,8 +711,7 @@ GPUARRAY_PUBLIC int GpuReduction_call (const GpuReduction*
712711
*/
713712

714713
static int reduxGetSumInit (int typecode, const char** property){
715-
if (typecode == GA_POINTER ||
716-
typecode == GA_BUFFER){
714+
if (typecode < 0){
717715
return GA_UNSUPPORTED_ERROR;
718716
}
719717
*property = "0";
@@ -732,8 +730,7 @@ static int reduxGetSumInit (int typecode, const char**
732730
*/
733731

734732
static int reduxGetProdInit (int typecode, const char** property){
735-
if (typecode == GA_POINTER ||
736-
typecode == GA_BUFFER){
733+
if (typecode < 0){
737734
return GA_UNSUPPORTED_ERROR;
738735
}
739736
*property = "1";
@@ -941,8 +938,7 @@ static int reduxGetMaxInit (int typecode, const char**
941938
*/
942939

943940
static int reduxGetAndInit (int typecode, const char** property){
944-
if (typecode == GA_POINTER ||
945-
typecode == GA_BUFFER){
941+
if (typecode < 0){
946942
return GA_UNSUPPORTED_ERROR;
947943
}
948944
*property = "~0";
@@ -961,8 +957,7 @@ static int reduxGetAndInit (int typecode, const char**
961957
*/
962958

963959
static int reduxGetOrInit (int typecode, const char** property){
964-
if (typecode == GA_POINTER ||
965-
typecode == GA_BUFFER){
960+
if (typecode < 0){
966961
return GA_UNSUPPORTED_ERROR;
967962
}
968963
*property = "0";
@@ -2858,7 +2853,7 @@ static int reduxGenCompile (GpuReduction* gr){
28582853
}
28592854

28602855
ret = GpuKernel_init(&gr->k,
2861-
gr->gpuCtx,
2856+
gr->grAttr.gpuCtx,
28622857
1,
28632858
(const char**)&gr->kSourceCode,
28642859
&gr->kSourceCodeLen,
@@ -3985,7 +3980,7 @@ static int reduxInvSchedule (redux_ctx* ctx){
39853980
ctx->W0Off = reduxGenGetWMEMK0Off(ctx->gr, 2*ctx->gs*ctx->D);
39863981
ctx->W1Off = reduxGenGetWMEMK1Off(ctx->gr, 2*ctx->gs*ctx->D);
39873982
WSPACESIZE = reduxGenGetWMEMSize (ctx->gr, 2*ctx->gs*ctx->D);
3988-
ctx->W = gpudata_alloc(ctx->gr->gpuCtx, WSPACESIZE, 0, flags, 0);
3983+
ctx->W = gpudata_alloc(ctx->gr->grAttr.gpuCtx, WSPACESIZE, 0, flags, 0);
39893984
if (!ctx->W){
39903985
return reduxInvCleanupMsg(ctx, GA_MEMORY_ERROR,
39913986
"Could not allocate %zu-byte workspace for reduction!\n",

0 commit comments

Comments
 (0)