Changeset: 62b7acafdfb5 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=62b7acafdfb5
Added Files:
monetdb5/extras/bwd/operations.c
monetdb5/extras/bwd/utilities.c
monetdb5/extras/bwd/utilities.h
Modified Files:
monetdb5/extras/bwd/Makefile.ag
monetdb5/extras/bwd/bwd.c
monetdb5/extras/bwd/opt_bwd.mal
monetdb5/extras/bwd/optimizer.c
Branch: bwd
Log Message:
* working on selections on bitwise decomposed data (this revision is compiling
but most probably broken)
Unterschiede (gekürzt von 654 auf 300 Zeilen):
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
@@ -29,7 +29,7 @@ lib_bwd = {
MODULE
DIR = libdir/monetdb5
SEP = _
- SOURCES = bwd.c optimizer.c
+ SOURCES = bwd.c optimizer.c operations.c utilities.c
LIBS = ../../tools/libmonetdb5 \
../../../gdk/libbat \
../../../common/stream/libstream \
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,5 +1,4 @@
#pragma GCC diagnostic ignored "-Wdeclaration-after-statement"
-/* #pragma GCC diagnostic warning "-Wpedantic" */
#include "monetdb_config.h"
#include "opt_statistics.h"
@@ -11,46 +10,8 @@
#include <CL/cl.h>
#endif
-#pragma mark Decomposed BAT Handling
-#define MAX_DECOMPOSED_BATS 1024
-static struct {
- unsigned char* approximation; //cl_mem
- size_t approximationBits;
- unsigned char* residuals;
-} bwdRegistry[MAX_DECOMPOSED_BATS] = {};
+#include "utilities.h"
-static const char* batRegistryIndex = "bwd.batRegistryIndex";
-
-static inline char batTailIsDecomposed(const BAT* subject){
- return BATgetprop(subject, batRegistryIndex) != NULL;
-}
-
-static inline const unsigned char*/* 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;
-}
-
-static inline size_t batTailApproximationBits(const BAT* subject){
- PROPrec* rightTailApproximationProperty;
- if(!(rightTailApproximationProperty = BATgetprop(subject,
batRegistryIndex))){
- THRprintf(GDKout, "#batTailApproximation: bat hasn't
been decomposed;\n");
- return 0;
- }
- return
bwdRegistry[rightTailApproximationProperty->v.val.ival].approximationBits;
-}
-
-static inline unsigned char* batTailResiduals(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].residuals;
-}
#pragma mark Storage Manipulation
@@ -58,64 +19,6 @@ static inline unsigned char* batTailResi
#define die(msg, args...) throw (MAL, "bwd", msg, args);
-char* cl_Errors[64];
-char* clError(int err){
- if (err == -1001)
- return "CL_PLATFORM_NOT_FOUND_KHR";
- if (!cl_Errors[0]){
- cl_Errors[0] = "CL_SUCCESS";
- cl_Errors[1] = "CL_DEVICE_NOT_FOUND";
- cl_Errors[2] = "CL_DEVICE_NOT_AVAILABLE";
- cl_Errors[3] = "CL_COMPILER_NOT_AVAILABLE";
- cl_Errors[4] = "CL_MEM_OBJECT_ALLOCATION_FAILURE";
- cl_Errors[5] = "CL_OUT_OF_RESOURCES";
- cl_Errors[6] = "CL_OUT_OF_HOST_MEMORY";
- cl_Errors[7] = "CL_PROFILING_INFO_NOT_AVAILABLE";
- cl_Errors[8] = "CL_MEM_COPY_OVERLAP";
- cl_Errors[9] = "CL_IMAGE_FORMAT_MISMATCH";
- cl_Errors[10] = "CL_IMAGE_FORMAT_NOT_SUPPORTED";
- cl_Errors[11] = "CL_BUILD_PROGRAM_FAILURE";
- cl_Errors[12] = "CL_MAP_FAILURE";
-
- cl_Errors[30] = "CL_INVALID_VALUE";
- cl_Errors[31] = "CL_INVALID_DEVICE_TYPE";
- cl_Errors[32] = "CL_INVALID_PLATFORM";
- cl_Errors[33] = "CL_INVALID_DEVICE";
- cl_Errors[34] = "CL_INVALID_CONTEXT";
- cl_Errors[35] = "CL_INVALID_QUEUE_PROPERTIES";
- cl_Errors[36] = "CL_INVALID_COMMAND_QUEUE";
- cl_Errors[37] = "CL_INVALID_HOST_PTR";
- cl_Errors[38] = "CL_INVALID_MEM_OBJECT";
- cl_Errors[39] = "CL_INVALID_IMAGE_FORMAT_DESCRIPTOR";
- cl_Errors[40] = "CL_INVALID_IMAGE_SIZE";
- cl_Errors[41] = "CL_INVALID_SAMPLER";
- cl_Errors[42] = "CL_INVALID_BINARY";
- cl_Errors[43] = "CL_INVALID_BUILD_OPTIONS";
- cl_Errors[44] = "CL_INVALID_PROGRAM";
- cl_Errors[45] = "CL_INVALID_PROGRAM_EXECUTABLE";
- cl_Errors[46] = "CL_INVALID_KERNEL_NAME";
- cl_Errors[47] = "CL_INVALID_KERNEL_DEFINITION";
- cl_Errors[48] = "CL_INVALID_KERNEL";
- cl_Errors[49] = "CL_INVALID_ARG_INDEX";
- cl_Errors[50] = "CL_INVALID_ARG_VALUE";
- cl_Errors[51] = "CL_INVALID_ARG_SIZE";
- cl_Errors[52] = "CL_INVALID_KERNEL_ARGS";
- cl_Errors[53] = "CL_INVALID_WORK_DIMENSION";
- cl_Errors[54] = "CL_INVALID_WORK_GROUP_SIZE";
- cl_Errors[55] = "CL_INVALID_WORK_ITEM_SIZE";
- cl_Errors[56] = "CL_INVALID_GLOBAL_OFFSET";
- cl_Errors[57] = "CL_INVALID_EVENT_WAIT_LIST";
- cl_Errors[58] = "CL_INVALID_EVENT";
- cl_Errors[59] = "CL_INVALID_OPERATION";
- cl_Errors[60] = "CL_INVALID_GL_OBJECT";
- cl_Errors[61] = "CL_INVALID_BUFFER_SIZE";
- cl_Errors[62] = "CL_INVALID_MIP_LEVEL";
- cl_Errors[63] = "CL_INVALID_GLOBAL_WORK_SIZE";
-
- }
- return cl_Errors[-err];
-}
-
char* clDeviceString(cl_device_type device_type){
switch(device_type){
case CL_DEVICE_TYPE_DEFAULT:
@@ -167,32 +70,7 @@ str deviceInfo(bat * resID, bat * resDes
return MAL_SUCCEED;
}
-int decomposeIntArray(const int* subject, const size_t size, const size_t
approximationBits){
- if (approximationBits % 8 > 0 || approximationBits <= 0) {
- THRprintf(GDKout, "#decomposeTail: number of bits for
approximation has to be a multiple of 8, is %ld;\n", approximationBits);
- return -1;
- }
- size_t i;
- for (i = 0; i < MAX_DECOMPOSED_BATS && bwdRegistry[i].residuals !=
NULL;)
- i++;
- const int newIndex = i;
- const register unsigned int residualBytes = (32-approximationBits)/8;
- const register unsigned int approximationBytes = approximationBits/8;
- bwdRegistry[newIndex].residuals = calloc((size+1)*residualBytes,
sizeof(char));
- bwdRegistry[newIndex].approximation =
calloc((size+1)*approximationBytes, sizeof(char));
- bwdRegistry[newIndex].approximationBits = approximationBits;
- const register unsigned int residualBits = 32-approximationBits;
- const register unsigned int residualMask = (1 << residualBits)-1;
- for (i = 0; i < size; ++i){
- *((unsigned int*)(bwdRegistry[newIndex].residuals +
i*residualBytes)) |= ((subject[i]&residualMask)<<approximationBits);
- *((unsigned int*)(bwdRegistry[newIndex].approximation +
i*approximationBytes)) |= (subject[i] >> residualBits);
-// THRprintf(GDKout, "#decomposeTail: approximation is %u,
residual is %u;\n", (*((unsigned int*)(bwdRegistry[newIndex].approximation +
i*approximationBytes))) << residualBits, (*((unsigned
int*)(bwdRegistry[newIndex].residuals + i*residualBytes))) >>
approximationBits);
- }
-
- THRprintf (GDKout, "decomposing bat registry index: %d\n", newIndex);
- return newIndex;
-}
str bwdecompose(bat * res, bat * subjectBAT, int* approximationBits){
BAT* subject = BATdescriptor(*subjectBAT);
@@ -206,60 +84,5 @@ str bwdecompose(bat * res, bat * subject
-#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){
- if(!batTailIsDecomposed(right))
- throw (MAL, "bwd.BWDLeftJoinApproximate", "bat is not
decomposed: %d", *r);
- BAT* result = BATnew(ATOMtype(left->htype),
ATOMtype(right->ttype), left->batCount);
- BATsetcount(result, left->batCount);
- bzero(Tloc(result, BUNfirst(result)),
left->batCount*sizeof(int));
- int i;
- int* outputRegion = (int*) Tloc(result, BUNfirst(result));
- const register unsigned char* approximation =
batTailApproximation(right);
- const register size_t approximationBytes =
batTailApproximationBits(right)/8;
- const register unsigned int residualBits =
32-batTailApproximationBits(right);
- const register size_t offset = left->tseqbase;
- for (i = 0; i < left->batCount; ++i)
- outputRegion[i] = (*((unsigned int*)(approximation +
(i+offset)*approximationBytes))) << residualBits;
-
- 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 * l, bat * r, bat * approx){
- ALGODEBUG THRprintf(GDKout, "#BWDfetchjoin: approximating;\n");
- BAT* left = BATdescriptor(*l);
- BAT* right = BATdescriptor(*r);
-
- BAT* approximation = BATdescriptor(*approx);
- BAT* refinement = BATnew(approximation->htype, approximation->ttype,
approximation->batCount);
- BATsetcount(refinement, approximation->batCount);
- if(BAThvoid(left) && BATtvoid(left) && BAThvoid(right) &&
right->tseqbase != oid_nil){
- if(!batTailIsDecomposed(right))
- throw (MAL, "bwd.BWDLeftJoinApproximate", "bat is not
decomposed: %d", *r);
- const unsigned char* residuals = batTailResiduals(right);
- const register size_t approximationBits =
batTailApproximationBits(right);
- const register unsigned int residualBytes =
(32-approximationBits)/8;
- int i;
- register int* outputRegion = (int*) Tloc(refinement,
BUNfirst(refinement));
- const register int* approximationRegion = (int*)
Tloc(approximation, BUNfirst(approximation));
- const register size_t offset = left->tseqbase;
- for (i = 0; i < approximation->batCount; ++i)
- outputRegion[i] = approximationRegion[i] +
((*((unsigned int*) (residuals + (i+offset)*residualBytes))) >>
approximationBits);
- }
- BBPkeepref(*res = refinement->batCacheid);
- BBPreleaseref(approximation->batCacheid);
- return MAL_SUCCEED;
-};
-
-
diff --git a/monetdb5/extras/bwd/operations.c b/monetdb5/extras/bwd/operations.c
new file mode 100644
--- /dev/null
+++ b/monetdb5/extras/bwd/operations.c
@@ -0,0 +1,136 @@
+#pragma GCC diagnostic ignored "-Wdeclaration-after-statement"
+
+#include "monetdb_config.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
+
+#include "utilities.h"
+
+#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){
+ if(!batTailIsDecomposed(right))
+ throw (MAL, "bwd.BWDLeftJoinApproximate", "bat is not
decomposed: %d", *r);
+ BAT* result = BATnew(ATOMtype(left->htype),
ATOMtype(right->ttype), left->batCount);
+ BATsetcount(result, left->batCount);
+ bzero(Tloc(result, BUNfirst(result)),
left->batCount*sizeof(int));
+ int i;
+ int* outputRegion = (int*) Tloc(result, BUNfirst(result));
+ const register size_t offset = left->tseqbase;
+ const register size_t approximationBytes =
batTailApproximationBits(right)/8;
+ const register unsigned int residualBits =
32-batTailApproximationBits(right);
+
+ void* approximation =
malloc(left->batCount*approximationBytes);
+ {
+ const cl_mem approximationObject =
batTailApproximation(right);
+ clEnqueueReadBuffer(getCommandQueue(),
batTailApproximation(right), CL_TRUE, offset*approximationBytes,
left->batCount*approximationBytes, approximation, 0, NULL, NULL);
+ }
+
+
+ for (i = 0; i < left->batCount; ++i)
+ outputRegion[i] = (*((unsigned int*)(approximation +
(i+offset)*approximationBytes))) << residualBits;
+
+ free(approximation);
+ 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 * l, bat * r, bat * approx){
+ ALGODEBUG THRprintf(GDKout, "#BWDfetchjoin: approximating;\n");
+ BAT* left = BATdescriptor(*l);
+ BAT* right = BATdescriptor(*r);
+
+ BAT* approximation = BATdescriptor(*approx);
+ BAT* refinement = BATnew(approximation->htype, approximation->ttype,
approximation->batCount);
+ BATsetcount(refinement, approximation->batCount);
+ if(BAThvoid(left) && BATtvoid(left) && BAThvoid(right) &&
right->tseqbase != oid_nil){
+ if(!batTailIsDecomposed(right))
+ throw (MAL, "bwd.BWDLeftJoinApproximate", "bat is not
decomposed: %d", *r);
+ const unsigned char* residuals = batTailResiduals(right);
+ const register size_t approximationBits =
batTailApproximationBits(right);
+ const register unsigned int residualBytes =
(32-approximationBits)/8;
+ int i;
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list