Changeset: 8433722c0dad for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=8433722c0dad
Modified Files:
gdk/gdk_bbp.mx
monetdb5/extras/bwd/bwd.c
monetdb5/extras/bwd/opt_bwd.mal
monetdb5/extras/bwd/optimizer_utilities.c
monetdb5/extras/bwd/optimizer_utilities.h
monetdb5/extras/bwd/pusher.c
monetdb5/optimizer/opt_pipes.c
sql/backends/monet5/sql_scenario.c
Branch: bwd
Log Message:
* implemented pushing of selections to the gpu
Unterschiede (296 Zeilen):
diff --git a/gdk/gdk_bbp.mx b/gdk/gdk_bbp.mx
--- a/gdk/gdk_bbp.mx
+++ b/gdk/gdk_bbp.mx
@@ -2757,10 +2757,12 @@ BBPdestroy(BAT *b)
(*tunfix) (BUNtail(bi, p));
}
}
- int j;
- for(j = 0; j<16; j++)
- if(registerBBPDestroyCallbacks[j])
- registerBBPDestroyCallbacks[j](&b->batCacheid);
+ {
+ int j;
+ for(j = 0; j<16; j++)
+ if(registerBBPDestroyCallbacks[j])
+
registerBBPDestroyCallbacks[j](&b->batCacheid);
+ }
clear = BBPaddtobin(b); /* plan for re-use */
}
if (clear)
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
@@ -124,33 +124,35 @@ str bwdecompose(bat * res, bat * subject
char* resolveBatToAttribute(bat bid, Client cntxt){
- mvc *m = NULL;
- sql_trans *tr = m->session->tr;
- node *nsch, *ntab, *ncol;
char* buffer = malloc(32);
+ if(0){
+ mvc *m = NULL;
+ sql_trans *tr = m->session->tr;
+ node *nsch, *ntab, *ncol;
- for( nsch= tr->schemas.set->h; nsch; nsch= nsch->next){
- sql_base *b= nsch->data;
- sql_schema *s= (sql_schema*) nsch->data;
- if ( isalpha((int)b->name[0]) )
+ for( nsch= tr->schemas.set->h; nsch; nsch= nsch->next){
+ sql_base *b= nsch->data;
+ sql_schema *s= (sql_schema*) nsch->data;
+ if ( isalpha((int)b->name[0]) )
- if (s->tables.set) for(ntab= (s)->tables.set->h ;ntab;
ntab= ntab->next){
- sql_base *bt= ntab->data;
- sql_table *t= (sql_table*) bt;
- if (isTable(t))
- if (t->columns.set) for (ncol=
(t)->columns.set->h; ncol; ncol= ncol->next){
- sql_base *bc =
ncol->data;
- sql_column *c=
(sql_column *) ncol->data;
- BAT *bn =
store_funcs.bind_col(tr, c, 0);
+ if (s->tables.set) for(ntab= (s)->tables.set->h
;ntab; ntab= ntab->next){
+ sql_base *bt= ntab->data;
+ sql_table *t= (sql_table*) bt;
+ if (isTable(t))
+ if (t->columns.set) for
(ncol= (t)->columns.set->h; ncol; ncol= ncol->next){
+
sql_base *bc = ncol->data;
+
sql_column *c= (sql_column *) ncol->data;
+ BAT *bn
= store_funcs.bind_col(tr, c, 0);
-
if(bn->batCacheid == bid){
- char*
buffer = malloc(strlen(bc->name) + strlen(bt->name)+15);
-
snprintf(buffer, strlen(bc->name) + strlen(bt->name)+15, "%s.%s (bat %d)",
bt->name, bc->name, bid);
- return
buffer;
+
if(bn->batCacheid == bid){
+
char* buffer = malloc(strlen(bc->name) + strlen(bt->name)+15);
+
snprintf(buffer, strlen(bc->name) + strlen(bt->name)+15, "%s.%s (bat %d)",
bt->name, bc->name, bid);
+
return buffer;
+ }
}
- }
- }
+ }
+ }
}
snprintf(buffer, 32, "%d", bid);
return buffer;
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
@@ -12,6 +12,8 @@ comment "Optimizer that pushes approxima
module bwd;
+
+
command leftjoinapproximate( left:bat[:any_1,:any_2], right:bat[:any_2,:any_3])
:bat[:any_1,:any_3]
address BWDLeftJoinApproximate
@@ -39,6 +41,10 @@ command uselectrefine(b:bat[:any_1,:any_
li:bit, hi:bit, approximation:bat[:any_1,:void] )
:bat[:any_1,:void]
address BWDUselectInclusiveRefine;
+command uselectrefine(b:bat[:any_1,:any_2], low:any_2, high:any_2,
+ li:bit, hi:bit, approximation:bat[:any_1,:any_2] )
:bat[:any_1,:void]
+address BWDUselectInclusiveRefine;
+
command semijoinapproximate( left:bat[:any_1,:any_2], right:bat[:any_1,:any] )
:bat[:any_1,:any_2]
address BWDSemijoinApproximate;
@@ -47,6 +53,14 @@ command semijoinrefine( left:bat[:any_1,
:bat[:any_1,:any_2]
address BWDSemijoinRefine;
+
+# This one is only temporarily implemented in mal
+function filter{inline} (tupleIds:bat[:oid,:void],
filterAttribute:bat[:oid,:int], low:int, high:int, li:bit, hi:bit)
:bat[:oid,:void];
+ projection := semijoinapproximate(filterAttribute, tupleIds);
+ return selection := bwd.uselectapproximate(projection, low, high, li, hi);
+end filter;
+
+
command multiplyapproximate(b1:bat[:oid,:any_1],b2:bat[:oid,:any_1])
:bat[:oid,:any_1]
address BWDBatMULsignalApproximate
comment "Return B1 * B2, signal error on overflow";
diff --git a/monetdb5/extras/bwd/optimizer_utilities.c
b/monetdb5/extras/bwd/optimizer_utilities.c
--- a/monetdb5/extras/bwd/optimizer_utilities.c
+++ b/monetdb5/extras/bwd/optimizer_utilities.c
@@ -1,12 +1,12 @@
#include "optimizer_utilities.h"
-int match_function(InstrPtr statement, char* moduleName, char* functionName) {
+int match_function(InstrPtr statement, const char* moduleName, const char*
functionName) {
return (statement->modname && !strcmp(statement->modname, moduleName)
&& !strcmp(statement->fcnname, functionName));
}
-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)));
+void rename_function(InstrPtr statement, const char* moduleName, const char*
functionName, int* actions, Client client) {
+ setModuleId(statement, putName((char*)moduleName, strlen(moduleName)));
+ setFunctionId(statement, putName((char*)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;
diff --git a/monetdb5/extras/bwd/optimizer_utilities.h
b/monetdb5/extras/bwd/optimizer_utilities.h
--- a/monetdb5/extras/bwd/optimizer_utilities.h
+++ b/monetdb5/extras/bwd/optimizer_utilities.h
@@ -2,7 +2,7 @@
#define _OPTIMIZER_UTILITIES_H_
#include "mal_interpreter.h"
-int match_function(InstrPtr statement, char* moduleName, char* functionName);
-void rename_function(InstrPtr statement, char* moduleName, char* functionName,
int* actions, Client client);
+int match_function(InstrPtr statement, const char* moduleName, const char*
functionName);
+void rename_function(InstrPtr statement, const char* moduleName, const char*
functionName, int* actions, Client client);
#endif /* _OPTIMIZER_UTILITIES_H_ */
diff --git a/monetdb5/extras/bwd/pusher.c b/monetdb5/extras/bwd/pusher.c
--- a/monetdb5/extras/bwd/pusher.c
+++ b/monetdb5/extras/bwd/pusher.c
@@ -8,19 +8,94 @@
#include "opt_statistics.h"
#include "optimizer_utilities.h"
+static const char* BWD = "bwd";
+/* static const char* MARK_T = "markT"; */
+
+
static inline int OPTBWDPusherImplementation(Client client, MalBlkPtr
malBlock, MalStkPtr stack, InstrPtr instruction){
uint i = 0;
- const InstrPtr* oldProgram = malBlock->stmt;
- const size_t instructionCount = malBlock->stop;
+ int actions = 0;
+ InstrPtr* oldProgram = malBlock->stmt;
+
+ const size_t instructionCount = malBlock->stop;
+ char* pushedInstructionCursors = malloc(sizeof(char)*instructionCount);
+ unsigned int* mapping = alloca(sizeof(unsigned int)*malBlock->vsize);
+ for (i = 0; i < (uint) malBlock->vsize; ++i)
+ mapping[i] = i;
+ for (i = 0; i < instructionCount; ++i)
+ pushedInstructionCursors[i] = 0;
+
newMalBlkStmt(malBlock, malBlock->ssize);
- while(!match_function(oldProgram[i], "bwd", "uselectapproximate") && i
< instructionCount){
+ i = 0;
+ while(!match_function(oldProgram[i], "bwd", "uselectapproximate")
+ && i < instructionCount){ // find first uselect
pushInstruction(malBlock, oldProgram[i]);
i++;
}
+
+
+ {
+ uint firstUselectStatement = i;
+ int filterPathTop = getDestVar(oldProgram[i]);
+ int selectionAttribute;
+ int* variableProducers =
malloc(sizeof(InstrPtr)*malBlock->vsize);
+ {
+ int k = 0;
+ for (; k < malBlock->vsize; ++k)
+ variableProducers[k] = 0;
+ }
+
+ pushInstruction(malBlock, oldProgram[i++]);
+
+ while(i < instructionCount){ // search for filters
+ variableProducers[getDestVar(oldProgram[i])] = i;
+ if(match_function(oldProgram[i], "bwd",
"uselectapproximate")){
+ InstrPtr filter = newInstruction(malBlock,
ASSIGNsymbol);
+ rename_function(filter, BWD, "filter",
&actions, client);
+ filter = pushReturn(malBlock, filter,
newTmpVariable(malBlock, getDestType(malBlock, oldProgram[i])));
+ filter = pushArgument(malBlock, filter,
filterPathTop);
+ filter = pushArgument(malBlock, filter,
selectionAttribute);
+ {
+ int argumentI = 2;
+ for (; argumentI < oldProgram[i]->argc;
++argumentI) {
+ if(argumentI < 4){
+
pushInstruction(malBlock,
copyInstruction(oldProgram[variableProducers[getArg(oldProgram[i],
argumentI)]]));
+
pushedInstructionCursors[variableProducers[getArg(oldProgram[i], argumentI)]] =
1;
+ }
+ filter = pushArgument(malBlock,
filter, getArg(oldProgram[i], argumentI));
+ }
+ }
+
+ pushInstruction(malBlock, filter);
+ filterPathTop = getDestVar(filter);
+ } else if(match_function(oldProgram[i], "bwd",
"semijoinapproximate")){
+ selectionAttribute = getArg(oldProgram[i], 1);
+ }
+
+ i++;
+ }
+ i = firstUselectStatement+1;
+ mapping[getDestVar(oldProgram[firstUselectStatement])] =
filterPathTop;
+ }
+
+ while(i < instructionCount){ // copy plans but filter out uselects
+ {
+ int j;
+ for (j = 0; j < oldProgram[i]->argc; ++j)
+ oldProgram[i]->argv[j] =
mapping[oldProgram[i]->argv[j]];
+ }
+ if(match_function(oldProgram[i], "bwd", "uselectapproximate")){
+ mapping[oldProgram[i]->argv[0]] =
oldProgram[i]->argv[1];
+ } else {
+ if(!pushedInstructionCursors[i])
+ pushInstruction(malBlock, oldProgram[i]);
+ }
+ i++;
+ }
- return 0;
+ return actions;
}
str OPTBWDPusher(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr p){
diff --git a/monetdb5/optimizer/opt_pipes.c b/monetdb5/optimizer/opt_pipes.c
--- a/monetdb5/optimizer/opt_pipes.c
+++ b/monetdb5/optimizer/opt_pipes.c
@@ -451,10 +451,26 @@ struct PIPELINES {
"optimizer.inline();"
"optimizer.remap();"
"optimizer.deadcode();"
+ "optimizer.evaluate();"
+ "optimizer.costModel();"
+ "optimizer.coercions();"
+ "optimizer.emptySet();"
+ "optimizer.aliases();"
+ "optimizer.deadcode();"
+ "optimizer.commonTerms();"
+ "optimizer.groups();"
+ "optimizer.joinPath();"
+ "optimizer.reorder();"
+ "optimizer.deadcode();"
+ "optimizer.reduce();"
+ "optimizer.history();"
"optimizer.bwd();"
+ "optimizer.bwdPusher();"
+ "optimizer.inline();"
"optimizer.multiplex();"
+ "optimizer.accumulators();"
"optimizer.garbageCollector();",
- "stable", 0, 0},
+ "experimental", "OPTBWD", 0},
};
#ifdef WIN32
diff --git a/sql/backends/monet5/sql_scenario.c
b/sql/backends/monet5/sql_scenario.c
--- a/sql/backends/monet5/sql_scenario.c
+++ b/sql/backends/monet5/sql_scenario.c
@@ -1605,7 +1605,7 @@ SQLparser(Client c)
finalize:
if (m->emod & mod_explain && !msg) {
if (be->q && be->q->code)
- printFunction(c->fdout, ((Symbol) (be->q->code))->def,
0, LIST_MAL_STMT | LIST_MAL_UDF | LIST_MAPI);
+ printFunction(c->fdout, ((Symbol) (be->q->code))->def,
0, LIST_MAL_STMT | LIST_MAL_UDF | LIST_MAPI | LIST_MAL_TYPE);
else if (c->curprg && c->curprg->def)
printFunction(c->fdout, c->curprg->def, 0,
LIST_MAL_STMT | LIST_MAL_UDF | LIST_MAPI);
}
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list