Skip to content

Commit

Permalink
Easy feedback fixes applied.
Browse files Browse the repository at this point in the history
  • Loading branch information
obilaniu committed Jul 25, 2017
1 parent 6d9e62d commit aa1d2e8
Showing 1 changed file with 17 additions and 22 deletions.
39 changes: 17 additions & 22 deletions src/gpuarray_reduction.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,6 @@ struct GpuReductionAttr{
struct GpuReduction{
/* Function Arguments. */
GpuReductionAttr grAttr;
gpucontext* gpuCtx;
ga_reduce_op op;
int nds;
int ndd;
int ndr;
Expand Down Expand Up @@ -651,6 +649,8 @@ GPUARRAY_PUBLIC void GpuReductionAttr_free (GpuReductionAttr*
}
GPUARRAY_PUBLIC int GpuReduction_new (GpuReduction** gr,
const GpuReductionAttr* grAttr){
GpuReduction* grOut = NULL;

if (!gr){
return GA_INVALID_ERROR;
}
Expand All @@ -659,16 +659,14 @@ GPUARRAY_PUBLIC int GpuReduction_new (GpuReduction**
return GA_INVALID_ERROR;
}

*gr = calloc(1, sizeof(**gr));
if (*gr){
(*gr)->grAttr = *grAttr;
(*gr)->gpuCtx = grAttr->gpuCtx;
(*gr)->op = grAttr->op;
(*gr)->nds = (int)grAttr->maxSrcDims;
(*gr)->ndd = (int)grAttr->maxDstDims;
(*gr)->ndr = (int)(grAttr->maxSrcDims-grAttr->maxDstDims);
grOut = calloc(1, sizeof(*grOut));
if (grOut){
grOut->grAttr = *grAttr;
grOut->nds = (int)grAttr->maxSrcDims;
grOut->ndd = (int)grAttr->maxDstDims;
grOut->ndr = (int)(grAttr->maxSrcDims - grAttr->maxDstDims);

return reduxGenInit(*gr);
return reduxGenInit(grOut);
}else{
return GA_MEMORY_ERROR;
}
Expand All @@ -683,7 +681,8 @@ GPUARRAY_PUBLIC int GpuReduction_call (const GpuReduction*
unsigned reduxLen,
const int* reduxList,
int flags){
redux_ctx ctxSTACK, *ctx = &ctxSTACK;
redux_ctx ctxSTACK;
redux_ctx *ctx = &ctxSTACK;
memset(ctx, 0, sizeof(*ctx));

ctx->gr = gr;
Expand Down Expand Up @@ -712,8 +711,7 @@ GPUARRAY_PUBLIC int GpuReduction_call (const GpuReduction*
*/

static int reduxGetSumInit (int typecode, const char** property){
if (typecode == GA_POINTER ||
typecode == GA_BUFFER){
if (typecode < 0){
return GA_UNSUPPORTED_ERROR;
}
*property = "0";
Expand All @@ -732,8 +730,7 @@ static int reduxGetSumInit (int typecode, const char**
*/

static int reduxGetProdInit (int typecode, const char** property){
if (typecode == GA_POINTER ||
typecode == GA_BUFFER){
if (typecode < 0){
return GA_UNSUPPORTED_ERROR;
}
*property = "1";
Expand Down Expand Up @@ -941,8 +938,7 @@ static int reduxGetMaxInit (int typecode, const char**
*/

static int reduxGetAndInit (int typecode, const char** property){
if (typecode == GA_POINTER ||
typecode == GA_BUFFER){
if (typecode < 0){
return GA_UNSUPPORTED_ERROR;
}
*property = "~0";
Expand All @@ -961,8 +957,7 @@ static int reduxGetAndInit (int typecode, const char**
*/

static int reduxGetOrInit (int typecode, const char** property){
if (typecode == GA_POINTER ||
typecode == GA_BUFFER){
if (typecode < 0){
return GA_UNSUPPORTED_ERROR;
}
*property = "0";
Expand Down Expand Up @@ -2858,7 +2853,7 @@ static int reduxGenCompile (GpuReduction* gr){
}

ret = GpuKernel_init(&gr->k,
gr->gpuCtx,
gr->grAttr.gpuCtx,
1,
(const char**)&gr->kSourceCode,
&gr->kSourceCodeLen,
Expand Down Expand Up @@ -3985,7 +3980,7 @@ static int reduxInvSchedule (redux_ctx* ctx){
ctx->W0Off = reduxGenGetWMEMK0Off(ctx->gr, 2*ctx->gs*ctx->D);
ctx->W1Off = reduxGenGetWMEMK1Off(ctx->gr, 2*ctx->gs*ctx->D);
WSPACESIZE = reduxGenGetWMEMSize (ctx->gr, 2*ctx->gs*ctx->D);
ctx->W = gpudata_alloc(ctx->gr->gpuCtx, WSPACESIZE, 0, flags, 0);
ctx->W = gpudata_alloc(ctx->gr->grAttr.gpuCtx, WSPACESIZE, 0, flags, 0);
if (!ctx->W){
return reduxInvCleanupMsg(ctx, GA_MEMORY_ERROR,
"Could not allocate %zu-byte workspace for reduction!\n",
Expand Down

0 comments on commit aa1d2e8

Please sign in to comment.