Changeset: 79be45d03965 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=79be45d03965
Modified Files:
monetdb5/extras/bwd/bwd.c
monetdb5/extras/bwd/operations.c
monetdb5/extras/bwd/opt_bwd.mal
monetdb5/extras/bwd/optimizer.c
monetdb5/extras/bwd/utilities.c
Branch: bwd
Log Message:
* working on grouping
* implemented batmirror (without testing it)
* making bwdgroupapproximate a wrapper for normal GRPgroup in order to
experiment with it
* rewriting group.done in plans
Unterschiede (206 Zeilen):
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
@@ -116,8 +116,12 @@ str bwdecompose(bat * res, bat * subject
BATsetprop(subject, batRegistryIndex, TYPE_int,
(int[]){decomposeIntArray((int*)Tloc(subject, BUNfirst(subject)),
subject->batCount, *approximationBits)});
snprintf(buffer, 4096, "successfully decomposed integer bat
%d", subject->batCacheid);
} else if(Tsize(subject) == 1){
- BATsetprop(subject, batRegistryIndex, TYPE_int,
(int[]){decomposeVarchar1Array(Tloc(subject, BUNfirst(subject)),
subject->batCount, Tsize(subject), Tbase(subject), *approximationBits)});
- snprintf(buffer, 4096, "successfully decomposed char bat %d",
subject->batCacheid);
+ if(approximationBits[0] > Tsize(subject)*8){
+ die("dude, bat %d only has %d bits, how am I supposed
to use %d bits for approximation\n", subject->batCacheid, Tsize(subject)*8,
approximationBits[0]);
+ } else {
+ BATsetprop(subject, batRegistryIndex, TYPE_int,
(int[]){decomposeVarchar1Array(Tloc(subject, BUNfirst(subject)),
subject->batCount, Tsize(subject), Tbase(subject), *approximationBits)});
+ snprintf(buffer, 4096, "successfully decomposed char
bat %d", subject->batCacheid);
+ }
} else {
snprintf(buffer, 4096, "bat %d cannot be decomposed because it
is not a 32 or 8-bit type", subject->batCacheid);
}
diff --git a/monetdb5/extras/bwd/operations.c b/monetdb5/extras/bwd/operations.c
--- a/monetdb5/extras/bwd/operations.c
+++ b/monetdb5/extras/bwd/operations.c
@@ -8,9 +8,9 @@
#include "algebra.h"
#include <math.h>
#include "opt_groups.h"
-
+#include "bat5.h"
#include "bwd.h"
-
+#include "group.h"
#if defined(HAVE_OPENCL_OPENCL_H)
#include <OpenCL/opencl.h>
#elif defined(HAVE_CL_CL_H)
@@ -43,6 +43,8 @@ void clock_gettime(int a, struct timespe
static const int CLOCK_THREAD_CPUTIME_ID;
#endif
+#define die(msg, args...) throw (MAL, "bwd", msg, args);
+
int getCount(cl_mem memoryObject){
cl_int err = 0;
int result;
@@ -716,8 +718,32 @@ str BWDtmark(int *res, int *bid, oid *ba
return returnValue;
}
-str BWDmirror(int *res, int *bid, oid *base){
- throw(MAL, __func__, "not implemented yet: %s", __func__);
+str BWDmirror(int *res, int *bid){
+ str returnValue = BKCmirror(res, bid);
+ if(*res){ // propagate head approximation
+ cl_int err;
+ BAT* input;
+ const unsigned int newIndex =
getNextFreeDecomposedBATSlotIndex();
+ DecomposedBATSlot* slot =
getDecomposedBATSlotForIndex(newIndex);
+ BAT* result = BATdescriptor(*res);
+ BATsetprop(result, batRegistryIndex, TYPE_int,
(int[]){newIndex});
+ BBPreleaseref(*res);
+ input = BATdescriptor(*bid);
+ if(!batHeadApproximation(input))
+ die("no head approximation in %s, %s:%d", __func__,
__FILE__, __LINE__);
+ slot->headApproximation = batHeadApproximation(input);
+ slot->tailApproximation = batHeadApproximation(input);
+ if(0) printf ("retaining %p\n", slot->headApproximation);
+ if((err=clRetainMemObject(slot->headApproximation)))
+ printf("#%s, clRetainMemObject: %s;\n", __func__,
clError(err));
+
+ if(0) printf ("retaining %p\n", slot->tailApproximation);
+ if((err=clRetainMemObject(slot->tailApproximation)))
+ printf("#%s, clRetainMemObject: %s;\n", __func__,
clError(err));
+
+ BBPreleaseref(*bid);
+ }
+ return returnValue;
}
@@ -1071,5 +1097,27 @@ str BWDjoinRefine(int *ret, int *lid, in
str BWDMulticolumnGroupApproximate(Client cntxt, MalBlkPtr mb, MalStkPtr stk,
InstrPtr pci){
- return GRPmulticolumngroup(cntxt, mb, stk, pci);
+ int *grp = (int*) getArgReference(stk,pci,0);
+ int *ext = (int*) getArgReference(stk,pci,1);
+ (void) grp;
+ (void) ext;
+ throw(MAL, __func__, "not implemented yet: %s", __func__);
+ return MAL_SUCCEED;// GRPmulticolumngroup(cntxt, mb, stk, pci);
}
+
+
+str BWDGroupApproximate(int *rethisto, int *retbid, int *bid){
+ // this function should be used as a template for new BWD-operators
+ GRPgroup(rethisto, retbid, bid);
+ // bn = BATnew(b->htype, TYPE_oid, BATcount(b));
+
+ throw(MAL, __func__, "not implemented yet: %s", __func__);
+}
+
+str BWDGroupRefine(int *rethisto, int *retbid, int *bid, int *apprrethisto,
int *apprretbid){
+ throw(MAL, __func__, "not implemented yet: %s", __func__);
+}
+
+str BWDMulticolumnGroupRefine(Client cntxt, MalBlkPtr mb, MalStkPtr stk,
InstrPtr pci){
+ throw(MAL, __func__, "not implemented yet: %s", __func__);
+}
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
@@ -154,9 +154,18 @@ address BWDMulticolumnGroupApproximate
comment "Approximate a group index over multiple columns.";
pattern
multicolumnsrefine(l:bat[:oid,:any]...)(grp:bat[:oid,:any],ext:bat[:oid,:any])
-address BWDMulticolumnGroupApproximate
+address BWDMulticolumnGroupRefine
comment "Refine a group index over multiple columns. (interface should be more
like: l:bat[:oid,:any],...,grp:bat[:oid,:any],ext:bat[:oid,:any])";
+command doneapproximate(attr:bat[:any_1,:any_2] )
+ (histo:bat[:any_1,:wrd], grp:bat[:any_1,:oid])
+address BWDGroupApproximate;
+
+command donerefine(attr:bat[:any_1,:any_2], histo:bat[:any_1,:wrd],
grp:bat[:any_1,:oid])
+ (histo:bat[:any_1,:wrd], grp:bat[:any_1,:oid])
+address BWDGroupRefine;
+
+
pattern exportValue{unsafe}(qtype:int, tname:str, name:str, typename:str,
digits:int, scale:int, eclass:int, val:any_1, w:str):void
diff --git a/monetdb5/extras/bwd/optimizer.c b/monetdb5/extras/bwd/optimizer.c
--- a/monetdb5/extras/bwd/optimizer.c
+++ b/monetdb5/extras/bwd/optimizer.c
@@ -83,6 +83,7 @@ static inline int OPTBWDImplementation(C
|| match_function(oldProgram[i], algebraRef,
semijoinRef)
|| match_function(oldProgram[i], algebraRef,
selectNotNilRef)
|| match_function(oldProgram[i], groupRef,
multicolumnsRef)
+ || match_function(oldProgram[i], groupRef, doneRef)
|| match_function(oldProgram[i], algebraRef, joinRef)
|| match_function(oldProgram[i], aggrRef, sumRef)
|| match_function(oldProgram[i], algebraRef,
leftjoinRef)) {
diff --git a/monetdb5/extras/bwd/utilities.c b/monetdb5/extras/bwd/utilities.c
--- a/monetdb5/extras/bwd/utilities.c
+++ b/monetdb5/extras/bwd/utilities.c
@@ -333,7 +333,7 @@ char* humanreadablesize(unsigned int val
}
void forceLoadOntoGPU(clTail* approximation, const size_t approximationSize,
DecomposedBATSlot* slot){
- static cl_program program = NULL;
+ cl_program program = NULL;
cl_int err;
cl_uint numberOfDevices;
cl_device_id devices[4] = {};
@@ -384,7 +384,7 @@ unsigned int decomposeIntArray(const int
const unsigned int residualMask = (1 << residualBits)-1;
const unsigned int approximationBits = neededBits-residualBits;
const size_t approximationSize = ceil(size*approximationBits/8.0) +
sizeof(long) + sizeof(clTail);
- clTail* approximation = calloc(approximationSize, sizeof(char));
+ clTail* approximation = GDKzalloc(approximationSize);
unsigned int i;
slot->tailOffsetBits = 32-neededBits;
@@ -393,7 +393,7 @@ unsigned int decomposeIntArray(const int
printf ("bounds: %d, %d, offset %zd bits\n",subjectBounds.min,
subjectBounds.max, slot->tailOffsetBits);
printf ("using %s for approximation and %s for residuals \n",
humanreadablesize(approximationSize, (char[64]){}, 64),
humanreadablesize(ceil(size*residualBits/8.0) + 8, (char[64]){}, 64));
- slot->residuals = calloc(ceil(size*residualBits/8.0) + 8, sizeof(char));
+ slot->residuals = GDKzalloc(ceil(size*residualBits/8.0) + 8);
approximation->base = subjectBounds.min;
slot->tailOffsetValue = approximation->base;
approximation->count = size;
@@ -423,7 +423,7 @@ unsigned int decomposeIntArray(const int
forceLoadOntoGPU(approximation, approximationSize, slot);
- free(approximation);
+ GDKfree(approximation);
return newIndex;
}
@@ -456,7 +456,7 @@ unsigned int decomposeVarchar1Array(cons
const unsigned int residualMask = (1 << residualBits)-1;
const unsigned int approximationBits = neededBits-residualBits;
const size_t approximationSize = ceil(size*approximationBits/8.0) +
sizeof(long) + sizeof(clTail);
- clTail* approximation = calloc(approximationSize, sizeof(char));
+ clTail* approximation = GDKzalloc(approximationSize);
unsigned int i;
slot->tailOffsetBits = 8-neededBits;
@@ -465,7 +465,7 @@ unsigned int decomposeVarchar1Array(cons
printf ("bounds: %d, %d, offset %zd bits\n",subjectBounds.min,
subjectBounds.max, slot->tailOffsetBits);
printf ("using %s for approximation and %s for residuals \n",
humanreadablesize(approximationSize, (char[64]){}, 64),
humanreadablesize(ceil(size*residualBits/8.0) + 8, (char[64]){}, 64));
- slot->residuals = calloc(ceil(size*residualBits/8.0) + 8, sizeof(char));
+ slot->residuals = GDKzalloc(ceil(size*residualBits/8.0) + 8);
approximation->base = subjectBounds.min;
slot->tailOffsetValue = approximation->base;
approximation->count = size;
@@ -496,7 +496,7 @@ unsigned int decomposeVarchar1Array(cons
forceLoadOntoGPU(approximation, approximationSize, slot);
- free(approximation);
+ GDKfree(approximation);
return newIndex;
}
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list