@@ -60,17 +60,6 @@ public abstract class RSTranslator extends BaseUserLibraryTranslator {
6060 + "\t \t <inputVar2> = rsGetElementAt_<varType>(<dataVar>, <x:{var|x, }><declBaseVar:{var|<baseVar> + }><xVar>);\n "
6161 + "\t \t <inputVar1> = <userFunctionName>(<inputVar1>, <inputVar2>);\n "
6262 + "\t }\n " + "\t return <inputVar1>;\n " ;
63- private static final String templateFilter = "\t int <varCount> = 0;\n "
64- + "\t for (int <xVar>=0; <xVar>\\ <rsAllocationGetDimX(<tileAllocation>); ++<xVar>) {\n "
65- + "<isImage:{var|\t for (int <yVar>=0; <yVar>\\ <rsAllocationGetDimY(<tileAllocation>); ++<yVar>) {\n }>"
66- + "\t \t int PM_value = rsGetElementAt_int(<tileAllocation>, <xVar><isImage:{var|, <yVar>}>);\n "
67- + "\t \t if (PM_value > 0) {\n "
68- + "\t \t \t rsSetElementAt_<type>(<outputAllocation>, rsGetElementAt_<type>(<inputAllocation>, PM_value), <varCount>++);\n "
69- + "\t \t }\n " + "<isImage:{var|\t \\ }\n }>" + "\t }\n " ;
70- private static final String templateParallelFilterTile = "\t if (<userFunctionName>(<varName><isImage:{var|, <xVar>, <yVar>}>)) {\n "
71- + "\t \t rsAtomicInc(&<varCounterName>);\n "
72- + "\t \t return x;\n "
73- + "\t } else {\n " + "\t \t return -1;\n " + "\t }\n " ;
7463 private static final String templateFunctionDecl = "<modifier:{var|<var.value> }><returnType><isKernel:{var| __attribute__((kernel))}> <functionName>("
7564 + "<params:{var|<var.type> <var.name>}; separator=\" , \" >)" ;
7665 private static final String templateAllocation = "Type <allocationName>Type = new Type.Builder(<rsVarName>, Element.<rsType>(<rsVarName>))\n "
@@ -79,14 +68,27 @@ public abstract class RSTranslator extends BaseUserLibraryTranslator {
7968 + "<declareAllocation:{var|Allocation }><allocationName> = Allocation.createTyped(<rsVarName>, <allocationName>Type);" ;
8069 private static String templateParallelForeachMapFunction = "\t return <userFunction>("
8170 + "<varName><isImage:{var|, x, y}>);\n " ;
82- private static String templateSequentialFunction = "\t for (int <xVar>=0; <xVar>\\ <rsAllocationGetDimX(<readAllocation>); ++<xVar>) {\n "
83- + "<isImage:{var|\t for (int <yVar>=0; <yVar>\\ <rsAllocationGetDimY(<readAllocation>); ++<yVar>) {\n }>"
84- + "\t \t \t <body>\n "
85- + "<isImage:{var|\t \\ }\n }>"
71+ private static String templateSequentialFunction = "<countVar:{var|int <var.name> = 0;\n }>"
72+ + "\t for (int <xVar>=0; <xVar>\\ <rsAllocationGetDimX(<readAllocation>); ++<xVar>) {\n "
73+ + "<isImage:{var|\t \t for (int <yVar>=0; <yVar>\\ <rsAllocationGetDimY(<readAllocation>); ++<yVar>) {\n }>"
74+ + "\t \t <body>\n "
75+ + "<isImage:{var|\t \t \\ }\n }>"
8676 + "\t }\n "
8777 + "<setExternalVariables:{var|\t \t rsSetElementAt_<var.type>(<var.allocationName>, <var.varName>, 0);\n }>" ;
8878 private static String templateSetValues = "rsSetElementAt_<typeSet>(<writeAllocation>, <userFunction>(rsGetElementAt_<typeGet>("
89- + "<readAllocation>, <xVar><isImage:{var|, <yVar>}>)), <xVar><isImage:{var|, <yVar>}>);" ;
79+ + "<readAllocation>, <xVar><isImage:{var|, <yVar>}>)<isImage:{var|, <xVar>, <yVar>}>), <notImageMap:{var|<xVar><isImage:{var|, <yVar>}>}>"
80+ + "<imageMap:{var|<countVar>++}>);" ;
81+ private static final String templateFilter = "\t int <varCount> = 0;\n "
82+ + "\t for (int <xVar>=0; <xVar>\\ <rsAllocationGetDimX(<tileAllocation>); ++<xVar>) {\n "
83+ + "<isImage:{var|\t for (int <yVar>=0; <yVar>\\ <rsAllocationGetDimY(<tileAllocation>); ++<yVar>) {\n }>"
84+ + "\t \t int PM_value = rsGetElementAt_int(<tileAllocation>, <xVar><isImage:{var|, <yVar>}>);\n "
85+ + "\t \t if (PM_value >= 0) {\n "
86+ + "\t \t \t rsSetElementAt_<type>(<outputAllocation>, rsGetElementAt_<type>(<inputAllocation>, PM_value), <varCount>++);\n "
87+ + "\t \t }\n " + "<isImage:{var|\t \\ }\n }>" + "\t }\n " ;
88+ private static final String templateParallelFilterTile = "\t if (<userFunctionName>(<varName><isImage:{var|, <xVar>, <yVar>}>)) {\n "
89+ + "\t \t rsAtomicInc(&<varCounterName>);\n "
90+ + "\t \t return x;\n "
91+ + "\t } else {\n " + "\t \t return -1;\n " + "\t }\n " ;
9092 private static String templateFilterOperationCall = "int <sizeVarName>[] = new int[1];\n "
9193 + "<kernelName>.get_<gSizeVariableName>().copyTo(<sizeVarName>);\n "
9294 + "if (<sizeVarName>[0] > 0) {\n "
@@ -95,7 +97,7 @@ public abstract class RSTranslator extends BaseUserLibraryTranslator {
9597 + "\t <variables:{var|\n \n \t <kernelName>.set_<var.gVariableName>(<var.variableName>);}>"
9698 + "<kernels:{var|\n \n \t <kernelName>.<var.rsOperationName>_<var.functionName>(<var.allocations>);}>"
9799 + "\n }" ;
98- private static String templateSequentialFilterTile = "if (<userFunction>(rsGetElementAt_<type>(<inputAllocation>, <xVar><isImage:{var|, <yVar>}>))) {\n "
100+ private static String templateSequentialFilterTile = "if (<userFunction>(rsGetElementAt_<type>(<inputAllocation>, <xVar><isImage:{var|, <yVar>}>)<isImage:{var|, <xVar>, <yVar>}> )) {\n "
99101 + "\t rsSetElementAt_int(<tileAllocation>, <xTileVar>, <xTileVar>);\n "
100102 + "\t <sizeVarName>++;\n "
101103 + "} else {\n "
@@ -294,11 +296,6 @@ private void fillForeachOperationCall(ST st, Operation operation) {
294296 commonDefinitions .getOperationName (operation ),
295297 variableAllocation + ", " + variableAllocation , "forEach" );
296298 }
297- boolean isImage = commonDefinitions .isImage (operation .variable );
298- String fromImageVar = commonDefinitions
299- .getFromImageBooleanName (operation .variable );
300- st .addAggr ("fromImage.{name, value}" , fromImageVar , isImage ? "true"
301- : "false" );
302299 }
303300
304301 /**
@@ -474,6 +471,13 @@ private String translateSequentialForeachMap(Operation operation) {
474471 st .add ("body" , getSetValuesInAllocations (operation , cType , typeGet ));
475472
476473 }
474+ if (commonDefinitions .isImage (operation .variable )
475+ && operation .operationType == OperationType .Map ) {
476+ st .addAggr ("countVar.{name}" , commonDefinitions .getPrefix ()
477+ + "count" );
478+ } else {
479+ st .add ("countVar" , null );
480+ }
477481 return createKernelFunction (operation , st .render (),
478482 FunctionType .BaseOperation );
479483 }
@@ -485,6 +489,15 @@ private String getSetValuesInAllocations(Operation operation,
485489 commonDefinitions .getOperationUserFunctionName (operation ));
486490 st .add ("typeSet" , typeSet );
487491 st .add ("typeGet" , typeGet );
492+ boolean isImage = commonDefinitions .isImage (operation .variable );
493+ if (operation .operationType == OperationType .Map ) {
494+ st .add ("notImageMap" , !isImage ? "" : null );
495+ st .add ("imageMap" , isImage ? "" : null );
496+ st .add ("countVar" , commonDefinitions .getPrefix () + "count" );
497+ } else {
498+ st .add ("notImageMap" , "" );
499+ st .add ("imageMap" , null );
500+ }
488501 setCommonParameters (operation , st );
489502 return st .render ();
490503 }
@@ -572,13 +585,16 @@ protected String translateParallelReduceTile(Operation operation) {
572585 commonDefinitions .getOperationUserFunctionName (operation ));
573586 st .add ("dataVar" , getInputDataVariableName (operation ));
574587 st .add ("dataVarTile" , getTileVariableName (operation ));
575- st .add ("sizeVar" ,
576- getAllocationDimCall ("X" , getTileVariableName (operation )));
577588 if (commonDefinitions .isImage (operation .variable )) {
589+ st .add ("sizeVar" ,
590+ getAllocationDimCall ("Y" ,
591+ getInputDataVariableName (operation )));
578592 st .add ("declBaseVar" , null );
579593 st .add ("baseVar" , "x, 0" );
580594 st .add ("x" , "" );
581595 } else {
596+ st .add ("sizeVar" ,
597+ getAllocationDimCall ("X" , getTileVariableName (operation )));
582598 st .add ("x" , null );
583599 st .add ("declBaseVar" , "" );
584600 st .add ("baseVar" , getBaseVariableName ());
@@ -668,6 +684,7 @@ private String translateParallelFilterTile(Operation operation) {
668684
669685 private String translateSequentialFilterTile (Operation operation ) {
670686 ST st = new ST (templateSequentialFunction );
687+ st .add ("countVar" , null );
671688 setCommonParameters (operation , st );
672689 setExternalVariables (operation , st );
673690 ST stBody = new ST (templateSequentialFilterTile );
0 commit comments