Changeset: 88c7507d16a0 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=88c7507d16a0
Added Files:
monetdb5/scheduler/mut_policy.c
monetdb5/scheduler/mut_policy.h
monetdb5/scheduler/mut_transforms.c
monetdb5/scheduler/mut_transforms.h
Modified Files:
monetdb5/scheduler/Makefile.ag
monetdb5/scheduler/run_mutation.c
Branch: mutation
Log Message:
Reshuffle code base
Prepare for a growing number of transforms and alternative policies.
diffs (truncated from 569 to 300 lines):
diff --git a/monetdb5/scheduler/Makefile.ag b/monetdb5/scheduler/Makefile.ag
--- a/monetdb5/scheduler/Makefile.ag
+++ b/monetdb5/scheduler/Makefile.ag
@@ -31,6 +31,8 @@ lib_scheduler = {
run_adder.c run_adder.h \
run_isolate.c run_isolate.h \
run_mutation.c run_mutation.h \
+ mut_transforms.c mut_transforms.h \
+ mut_policy.c mut_policy.h \
run_memo.c run_memo.h \
run_octopus.c run_octopus.h \
srvpool.c srvpool.h \
diff --git a/monetdb5/scheduler/mut_policy.c b/monetdb5/scheduler/mut_policy.c
new file mode 100644
--- /dev/null
+++ b/monetdb5/scheduler/mut_policy.c
@@ -0,0 +1,116 @@
+/*
+ * The contents of this file are subject to the MonetDB Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.monetdb.org/Legal/MonetDBLicense
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is the MonetDB Database System.
+ *
+ * The Initial Developer of the Original Code is CWI.
+ * Portions created by CWI are Copyright (C) 1997-July 2008 CWI.
+ * Copyright August 2008-2013 MonetDB B.V.
+ * All Rights Reserved.
+ */
+
+/*
+ * @f run_mutation
+ * @a M. Kersten, M. Gawade
+ * Run mutated query plans
+ * The infrastructure to adapatively create multi-processor parallel plans.
+ */
+#include "monetdb_config.h"
+#include "run_mutation.h"
+#include "mut_transforms.h"
+#include "mal_profiler.h"
+#include "opt_prelude.h"
+#include "mut_policy.h"
+
+
+/*
+ * For the time being we focus on a limited set op MAL instructions.
+ */
+static int
+mutationCandidate(MalBlkPtr mb, InstrPtr p){
+ (void) mb;
+ if ( getModuleId(p) == algebraRef)
+ return 1;
+ if ( getModuleId(p) == aggrRef)
+ return 1;
+ return 0;
+}
+
+
+str
+MUTpolicy(Client cntxt, Mutant m)
+{
+ MalBlkPtr src = m->src;
+ MalStkPtr stk = m->stk;
+ int i, target = 0, stop, vtop;
+ InstrPtr p;
+
+ (void) cntxt;
+
+ m->target = 0;
+ // Find an expensive instruction to replace
+ if ( src->profiler && src->calls)
+ for ( i = 2; i < src->stop ; i++) {
+ p = getInstrPtr(src,i);
+ if ( p->barrier)
+ continue; // ignore block structures
+ if ( !mutationCandidate(src, p))
+ continue;
+ DEBUG_MUTATION
+ mnstr_printf(cntxt->fdout,"#mutation candidate %d cost
"LLFMT"\n", i, src->profiler[i].ticks/src->calls);
+
+ if ( m->target == 0)
+ m->target = i;
+ else
+ if ( src->profiler[i].ticks/src->calls >
src->profiler[target].ticks/src->calls)
+ m->target = i;
+ }
+ DEBUG_MUTATION if ( src->profiler && m->target) {
+ mnstr_printf(cntxt->fdout,"#mutation calls %d cost "LLFMT"\n",
src->calls, src->runtime/src->calls);
+ mnstr_printf(cntxt->fdout,"#mutation target instruction %d cost
"LLFMT"\n", m->target, src->profiler[target].ticks/src->calls);
+
printInstruction(cntxt->fdout,src,0,getInstrPtr(src,target),LIST_MAL_ALL);
+ }
+ /* At this point we have a target instruction to be replaced */
+ /* safe the previous version in the history list */
+ if ( mutationCandidate(src, p = getInstrPtr(src, m->target)) ){
+ stop = src->stop;
+ vtop = src->vtop;
+
+ /* apply heuristics */
+ if ( getModuleId(p) && strncmp(getModuleId(p), "algebra",7)== 0)
+ mutationSelect(cntxt,m);
+ if ( getModuleId(p) && strncmp(getModuleId(p), "aggr",4)== 0)
+ mutationSum(cntxt,m);
+
+ /* reset/expand the profiler */
+ if ( stop < src->stop){
+ GDKfree(src->profiler);
+ src->profiler = 0;
+ initProfiler(src);
+ }
+ for( i = 0; i < src->stop; i++)
+ src->profiler[i].ticks = 0;
+
+ /* initialize the possibly expanded stack frame */
+ if ( vtop < src->vtop){
+ stk= (MalStkPtr) GDKrealloc(stk, stackSize(src->vtop) +
sizeof(MalStack));
+ for (i = vtop ; i< src->vtop; i++)
+ stk->stk[i].val.lval = 0;
+ }
+ src->calls = 0;
+ chkProgram(cntxt->fdout,cntxt->nspace,src);
+ DEBUG_MUTATION
+ printFunction(cntxt->fdout, src,0,LIST_MAL_ALL);
+ if ( src->errors)
+ throw(MAL,"run_mutation","Internal error");
+ }
+ return MAL_SUCCEED;
+}
diff --git a/monetdb5/scheduler/mut_policy.h b/monetdb5/scheduler/mut_policy.h
new file mode 100644
--- /dev/null
+++ b/monetdb5/scheduler/mut_policy.h
@@ -0,0 +1,30 @@
+/*
+ * The contents of this file are subject to the MonetDB Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.monetdb.org/Legal/MonetDBLicense
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is the MonetDB Database System.
+ *
+ * The Initial Developer of the Original Code is CWI.
+ * Portions created by CWI are Copyright (C) 1997-July 2008 CWI.
+ * Copyright August 2008-2013 MonetDB B.V.
+ * All Rights Reserved.
+ */
+
+#ifndef _MUT_POLICY_
+#define _MUT_POLICY_
+#include "mal.h"
+#include "mal_instruction.h"
+#include "mal_interpreter.h"
+#include "mal_client.h"
+#include "run_mutation.h"
+
+run_mutation_export str MUTpolicy(Client cntxt, Mutant m);
+#endif /* _MUT_POLICY_ */
+
diff --git a/monetdb5/scheduler/mut_transforms.c
b/monetdb5/scheduler/mut_transforms.c
new file mode 100644
--- /dev/null
+++ b/monetdb5/scheduler/mut_transforms.c
@@ -0,0 +1,123 @@
+/*
+ * The contents of this file are subject to the MonetDB Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.monetdb.org/Legal/MonetDBLicense
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is the MonetDB Database System.
+ *
+ * The Initial Developer of the Original Code is CWI.
+ * Portions created by CWI are Copyright (C) 1997-July 2008 CWI.
+ * Copyright August 2008-2013 MonetDB B.V.
+ * All Rights Reserved.
+ */
+
+/*
+ * @f run_mutation
+ * @a M. Kersten, M. Gawade
+ * Run mutated query plans
+ * The infrastructure to adapatively create multi-processor parallel plans.
+ */
+#include "monetdb_config.h"
+#include "mut_transforms.h"
+#include "mal_profiler.h"
+#include "opt_prelude.h"
+
+/* Sample plan mutation actions
+ * The select mutation simply splits the target instruction
+ * and glues the result using matpack.
+ */
+void
+mutationSelect(Client cntxt, Mutant m){
+ int pc = m->target, i,limit, b1,b2, v1,v2;
+ InstrPtr p=0, *old= m->src->stmt, q;
+
+ (void) cntxt;
+ limit= m->src->stop;
+ if ( newMalBlkStmt(m->src, m->src->ssize) < 0)
+ return;
+
+ pushInstruction(m->src, old[0]);
+ for (i = 1; i < limit; i++) {
+ p= old[i];
+ if ( i == pc){
+ /* replace the instruction, e.g. with a partioned one.
+ Dont use any partition intelligence, simple half
split
+ v := algebra.select(b,l,h) =>
+ b1 := bat.partition(b,2,0);
+ b2 := bat.partition(b,2,1);
+ v1:= algebra.select(b1,l,h);
+ v2:= algebra.select(b2,l,h);
+ v:= mat.pack(v1,v2);
+ Also initialize the corresponding stk, which may
actually
+ have to be extended.
+ */
+ q= newStmt(m->src, batRef, partitionRef);
+ setVarType(m->src, getArg(q,0), getArgType(m->src, p,
p->retc));
+ b1 = getArg(q,0);
+ q = pushArgument(m->src,q,getArg(p,1));
+ q = pushInt(m->src,q,2);
+ q = pushInt(m->src,q,0);
+
+ q= newStmt(m->src, batRef, partitionRef);
+ setVarType(m->src, getArg(q,0), getArgType(m->src, p,
p->retc));
+ b2 = getArg(q,0);
+ q = pushArgument(m->src,q,getArg(p,1));
+ q = pushInt(m->src,q,2);
+ q = pushInt(m->src,q,1);
+
+ q= copyInstruction(p);
+ getArg(q,1)= b1;
+ v1 = getArg(q,0)= newTmpVariable(m->src,TYPE_any);
+ pushInstruction(m->src,q);
+ q= copyInstruction(p);
+ getArg(q,1)= b2;
+ v2 = getArg(q,0)= newTmpVariable(m->src,TYPE_any);
+ pushInstruction(m->src,q);
+
+ q= newStmt(m->src,matRef,packRef);
+ getArg(q,0)= getArg(p,0);
+ q= pushArgument(m->src,q,v1);
+ q= pushArgument(m->src,q,v2);
+
+ //pushInstruction(m->src,p);
+ m->target = pc;
+ m->comment = GDKstrdup("mutationSelect");
+ } else
+ pushInstruction(m->src,p);
+ }
+ GDKfree(old);
+}
+/*
+ * The aggr.sum operation performs parallel sums
+ * and consolidates the result
+ */
+void
+mutationSum(Client cntxt, Mutant m){
+ int pc = m->target, i, limit;
+ InstrPtr p=0, *old= m->src->stmt;
+
+ (void) cntxt;
+ limit= m->src->stop;
+ if ( newMalBlkStmt(m->src, m->src->ssize) < 0)
+ return;
+
+ pushInstruction(m->src, old[0]);
+ for (i = 1; i < limit; i++) {
+ p= old[i];
+ if ( i == pc){
+ /* replace the instruction, e.g. with a partioned one */
+ pushInstruction(m->src,p);
+ m->target = pc;
+ m->comment = GDKstrdup("mutationSum");
+ } else
+ pushInstruction(m->src,p);
+ }
+ GDKfree(old);
+}
+
diff --git a/monetdb5/scheduler/mut_transforms.h
b/monetdb5/scheduler/mut_transforms.h
new file mode 100644
--- /dev/null
+++ b/monetdb5/scheduler/mut_transforms.h
_______________________________________________
checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list