Changeset: cc37478e00d5 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=cc37478e00d5
Added Files:
        monetdb5/extras/bwd/91_bwd.sql
Modified Files:
        monetdb5/extras/bwd/91_opt_bwd.mal
        monetdb5/extras/bwd/Makefile.ag
        monetdb5/extras/bwd/bwd.c
        monetdb5/extras/bwd/opt_bwd.mal
Branch: bwd
Log Message:

* created framework for bwd (storage management as well as processing)


Unterschiede (232 Zeilen):

diff --git a/monetdb5/extras/bwd/91_bwd.sql b/monetdb5/extras/bwd/91_bwd.sql
new file mode 100644
--- /dev/null
+++ b/monetdb5/extras/bwd/91_bwd.sql
@@ -0,0 +1,2 @@
+create function bwdecompose(col integer, bits integer)
+returns integer external name bwd.decompose;
diff --git a/monetdb5/extras/bwd/91_opt_bwd.mal 
b/monetdb5/extras/bwd/91_opt_bwd.mal
--- a/monetdb5/extras/bwd/91_opt_bwd.mal
+++ b/monetdb5/extras/bwd/91_opt_bwd.mal
@@ -0,0 +1,3 @@
+library bwd;
+
+include opt_bwd;
\ No newline at end of file
diff --git a/monetdb5/extras/bwd/Makefile.ag b/monetdb5/extras/bwd/Makefile.ag
--- a/monetdb5/extras/bwd/Makefile.ag
+++ b/monetdb5/extras/bwd/Makefile.ag
@@ -20,7 +20,8 @@ INCLUDES = \
        ../../mal \
        ../../../gdk \
        ../../../common/stream \
-       ../../../common/options
+       ../../../common/options \
+       $(OPENCL_CFLAGS)
 
 MTSAFE
 
@@ -32,9 +33,17 @@ lib_bwd = {
        LIBS = ../../tools/libmonetdb5 \
                ../../../gdk/libbat \
                ../../../common/stream/libstream \
-               $(MALLOC_LIBS)
+               $(MALLOC_LIBS) \
+               $(OPENCL_LIBS)
 }
 
+headers_sql = {
+       HEADERS = sql
+       DIR = libdir/monetdb5/createdb
+       SOURCES = 91_bwd.sql
+}
+
+
 headers_mal = {
        HEADERS = mal
        DIR = libdir/monetdb5
diff --git a/monetdb5/extras/bwd/bwd.c b/monetdb5/extras/bwd/bwd.c
--- a/monetdb5/extras/bwd/bwd.c
+++ b/monetdb5/extras/bwd/bwd.c
@@ -1,10 +1,146 @@
+#pragma GCC diagnostic warning "-Wdeclaration-after-statement"
+/* #pragma GCC diagnostic warning "-Wpedantic" */
+
 #include "monetdb_config.h"
 #include "mal_interpreter.h"
 #include "opt_statistics.h"
 #include "bwd.h"
 
+/* #if defined(HAVE_OPENCL_OPENCL_H) */
+#include <OpenCL/opencl.h>
+/* #elif defined(HAVE_CL_CL_H) */
+/* #include <CL/cl.h> */
+/* #endif */
 
-str OPTBWDImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr 
p){
+
+static inline int match_function(InstrPtr statement, char* moduleName, char* 
functionName) {
+       return (statement->modname && !strcmp(statement->modname, moduleName) 
&& !strcmp(statement->fcnname, functionName));
+}
+
+static inline void rename_function(InstrPtr statement, char* moduleName, char* 
functionName, int* actions, Client client) {
+       setModuleId(statement, putName(moduleName, strlen(moduleName)));
+       setFunctionId(statement, putName(functionName, strlen(functionName)));
+       if(statement->token == CMDcall){
+               if(findSymbol(client->nspace, statement->modname, 
statement->fcnname))
+                       statement->fcn = findSymbol(client->nspace, 
statement->modname, statement->fcnname)->def->stmt[0]->fcn;
+               else
+                       printf("didn't find function definition for %s.%s", 
moduleName, functionName);
+       }
+       actions[0]++;
+};
+
+
+#pragma mark Decomposed BAT Handling
+
+static struct {
+       cl_mem approximation;
+       void* residuals;
+} bwdRegistry[1024] = {};
+
+static const char* batRegistryIndex = "bwd.batRegistryIndex";
+
+static inline char batTailIsDecomposed(const BAT* subject){
+       return BATgetprop(subject, batRegistryIndex) != NULL;
+}
+
+static inline cl_mem batTailApproximation(const BAT* subject){
+               PROPrec* rightTailApproximationProperty;
+               if(!(rightTailApproximationProperty = BATgetprop(subject, 
batRegistryIndex))){
+                       THRprintf(GDKout, "#batTailApproximation: bat hasn't 
been decomposed;\n");
+                       return NULL;
+               }
+               return 
bwdRegistry[rightTailApproximationProperty->v.val.ival].approximation;
+}
+
+
+#pragma mark Storage Manipulation
+
+
+
+void decomposeTail(const BAT* subject, size_t approximationBits){
+       if (approximationBits % 8 > 0) 
+               THRprintf(GDKout, "#decomposeTail: number of bits for 
approximation has to be a multiple of 8, is %ld;\n", approximationBits);
+
+       for (int i = 0; i < subject->batCount; ++i) {
+               
+       }
+}
+
+str bwdecompose(bat * res, bat * subjectBAT, int* approximationBits){
+       THRprintf (GDKout, "decomposing bat %d into %d and %d 
bits\n",subjectBAT[0], approximationBits[0], 0);
+       BAT* subject = BATdescriptor(*subjectBAT);
+       BBPkeepref(*res = BATcopy(subject, subject->htype, subject->ttype, 
TRUE)->batCacheid);
+       return MAL_SUCCEED;
+}
+
+
+
+#pragma mark Actual MAL Operations Implementation
+
+str BWDLeftJoinApproximate(bat * res, bat * l, bat * r){
+       ALGODEBUG THRprintf(GDKout, "#BWDfetchjoin: approximating;\n");
+       BAT* left = BATdescriptor(*l);
+       BAT* right = BATdescriptor(*r);
+       if(BAThvoid(left) && BATtvoid(left) && BAThvoid(right) && 
right->tseqbase != oid_nil){
+                       BAT* result = BATnew(ATOMtype(left->htype), 
ATOMtype(right->ttype), left->batCount);
+                       BATsetcount(result, left->batCount);
+                       if(batTailIsDecomposed(right)){
+                               
+                       }
+                       
+                       BBPkeepref((*res = result->batCacheid));
+                       BBPreleaseref(left->batCacheid);
+                       BBPreleaseref(right->batCacheid);
+                       return MAL_SUCCEED;
+       }       else
+               throw(MAL, "bwd.BWDLeftJoinApproximate", "%s (BAThvoid(left): 
%d, BATtvoid(left): %d, BAThvoid(right): %d, right->tseqbase: %ld)", "this case 
isn't implemented yet",   BAThvoid(left), BATtvoid(left), BATtvoid(right), 
left->tseqbase);
+};
+
+
+str BWDLeftJoinRefine(bat * res, bat * left, bat * right, bat * approx){
+       BAT* approximation = BATdescriptor(*approx);
+       BAT* refinement = BATcopy(approximation, approximation->htype, 
approximation->ttype, TRUE);
+       BBPkeepref(*res = refinement->batCacheid);
+       BBPreleaseref(approximation->batCacheid);
+       return MAL_SUCCEED;
+};
+
+
+static inline int OPTBWDImplementation(Client client, MalBlkPtr malBlock, 
MalStkPtr stack, InstrPtr instruction){
+       InstrPtr* oldProgram = malBlock->stmt;
+       size_t instructionCount = malBlock->stop;
+       
+       newMalBlkStmt(malBlock, malBlock->ssize + 1);
+       int i;
+       for (i = 0; i < instructionCount; ++i) {
+               if(match_function(oldProgram[i], "algebra", "leftjoin")){
+                       int approximateResultVariable = 
newTmpVariable(malBlock, getDestType(malBlock, oldProgram[i]));
+                       {
+                               
+                               InstrPtr approximateLeftjoin = 
newInstruction(malBlock, ASSIGNsymbol);
+                               rename_function(approximateLeftjoin, "bwd", 
"leftjoinapproximate", (int[]){0}, client);
+                               setDestVar(approximateLeftjoin, 
approximateResultVariable);
+                               int j;
+                               for (j = 1; j < oldProgram[i]->argc; ++j) 
+                                       approximateLeftjoin = 
pushArgument(malBlock, approximateLeftjoin, getArg(oldProgram[i], j));
+                               pushInstruction(malBlock, approximateLeftjoin);
+                       }
+                       {
+                               InstrPtr refineLeftjoin = 
newInstruction(malBlock, ASSIGNsymbol);
+                               rename_function(refineLeftjoin, "bwd", 
"leftjoinrefine", (int[]){0}, client);
+                               setDestVar(refineLeftjoin, 
getDestVar(oldProgram[i]));
+                               int j;
+                               for (j = 1; j < oldProgram[i]->argc; ++j) 
+                                       refineLeftjoin = pushArgument(malBlock, 
refineLeftjoin, getArg(oldProgram[i], j));
+                               refineLeftjoin = pushArgument(malBlock, 
refineLeftjoin, approximateResultVariable);
+                               pushInstruction(malBlock, refineLeftjoin);
+                       }
+               } else {
+                       pushInstruction(malBlock, oldProgram[i]);
+               }
+       }
+       printf ("rewriting plan for bwd\n");
+       return 0;
 }
 
 str OPTBWD(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr p){
diff --git a/monetdb5/extras/bwd/opt_bwd.mal b/monetdb5/extras/bwd/opt_bwd.mal
--- a/monetdb5/extras/bwd/opt_bwd.mal
+++ b/monetdb5/extras/bwd/opt_bwd.mal
@@ -2,4 +2,28 @@ pattern optimizer.bwd():str
 address OPTBWD;
 pattern optimizer.bwd(mod:str, fcn:str):str
 address OPTBWD
-comment "Optimizer that inserts statements to approximate results of 
operations using Bitwise Decomposition";
\ No newline at end of file
+comment "Optimizer that inserts statements to approximate results of 
operations using Bitwise Decomposition";
+
+module bwd;
+
+command leftjoinapproximate( left:bat[:any_1,:any_2], right:bat[:any_2,:any_3])
+               :bat[:any_1,:any_3] 
+address BWDLeftJoinApproximate
+comment "yields an (over)approximation of a classic monetdb leftjoin";
+
+command leftjoinrefine( left:bat[:any_1,:any_2], right:bat[:any_2,:any_3], 
kickstart:bat[:any_1,:any_3])
+               :bat[:any_1,:any_3] 
+address BWDLeftJoinRefine
+comment "yields a refinement of an (over)approximation, i.e., an accurate 
result of a classic monetdb leftjoin";
+
+
+
+
+command decompose(column:int, approximationBits: int):void
+address bwdecomposeScalar;
+
+module batbwd;
+
+command decompose(col:bat[:oid,:int],bits:int):bat[:oid,:int]
+address bwdecompose;
+
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to