Changeset: ee8f332df1f5 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=ee8f332df1f5
Added Files:
monetdb5/extras/bwd/optimizer.c
Modified Files:
monetdb5/extras/bwd/91_bwd.sql
monetdb5/extras/bwd/Makefile.ag
monetdb5/extras/bwd/bwd.c
monetdb5/extras/bwd/bwd.h
monetdb5/extras/bwd/opt_bwd.mal
Branch: bwd
Log Message:
* added bwdevices function to check for available opencl devices
* some refactoring
Unterschiede (gekürzt von 569 auf 300 Zeilen):
diff --git a/monetdb5/extras/bwd/91_bwd.sql b/monetdb5/extras/bwd/91_bwd.sql
--- a/monetdb5/extras/bwd/91_bwd.sql
+++ b/monetdb5/extras/bwd/91_bwd.sql
@@ -1,2 +1,6 @@
create function bwdecompose(col integer, bits integer)
returns integer external name bwd.decompose;
+
+
+create function bwdevices()
+returns table(id int, description string) external name bwd.deviceInfo;
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
+ SOURCES = bwd.c optimizer.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,41 +1,18 @@
-#pragma GCC diagnostic warning "-Wdeclaration-after-statement"
+#pragma GCC diagnostic ignored "-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 */
-
-
-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
-
+#define MAX_DECOMPOSED_BATS 1024
static struct {
- cl_mem approximation;
- void* residuals;
-} bwdRegistry[1024] = {};
+ unsigned char* approximation; //cl_mem
+ size_t approximationBits;
+ unsigned char* residuals;
+} bwdRegistry[MAX_DECOMPOSED_BATS] = {};
static const char* batRegistryIndex = "bwd.batRegistryIndex";
@@ -43,7 +20,7 @@ static inline char batTailIsDecomposed(c
return BATgetprop(subject, batRegistryIndex) != NULL;
}
-static inline cl_mem batTailApproximation(const BAT* subject){
+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");
@@ -52,23 +29,172 @@ static inline cl_mem batTailApproximatio
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
+#define die(msg, args...) throw (MAL, "bwd", msg, args);
-void decomposeTail(const BAT* subject, size_t approximationBits){
- if (approximationBits % 8 > 0)
+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:
+ return "CL_DEVICE_TYPE_DEFAULT";
+ case CL_DEVICE_TYPE_CPU:
+ return "CL_DEVICE_TYPE_CPU";
+ case CL_DEVICE_TYPE_GPU:
+ return "CL_DEVICE_TYPE_GPU";
+ case CL_DEVICE_TYPE_ACCELERATOR:
+ return "CL_DEVICE_TYPE_ACCELERATOR";
+ }
+ return "unkown";
+}
+
+str deviceInfo(bat * resID, bat * resDesc){
+ BAT* result = BATnew(TYPE_void, TYPE_int, 2);
+ BAT* resultDesc = BATnew(TYPE_void, TYPE_str, 2);
+ BATsetcount(result, 0);
+ BATsetcount(resultDesc, 0);
+ {
+ cl_uint numPlatforms;
+ int err;
+ if((err = clGetPlatformIDs(0, NULL, &numPlatforms)))
+ die ("clGetPlatformIDs error: %s\n", clError(err));
+
+ cl_platform_id* platforms =
malloc(sizeof(cl_platform_id)*numPlatforms);
+ if((err = clGetPlatformIDs(numPlatforms, platforms,
&numPlatforms)))
+ die ("clGetPlatformIDs error: %s\n",clError(err));
+
+ for(int i = 0; i<numPlatforms;i++){
+ cl_device_id devices[8];
+ cl_uint numberOfDevices = 0;
+
clGetDeviceIDs(platforms[i],CL_DEVICE_TYPE_ALL,8,devices,&numberOfDevices);
+ for (int i = 0; i < numberOfDevices; ++i){
+ cl_device_type device_type;
+
clGetDeviceInfo(devices[i],CL_DEVICE_TYPE,sizeof(cl_ulong),&device_type,NULL);
+ char deviceName[1024];
+ if((err =
clGetDeviceInfo(devices[i],CL_DEVICE_NAME,sizeof(deviceName),&deviceName,NULL)))
die ("clGetDeviceInfo error: %s\n",clError(err));
+ char buffer[1024];
+ snprintf (buffer, 1024, "%s (%s)\n",
deviceName, clDeviceString(device_type));
+ BUNappend(resultDesc, buffer, 0);
+ BUNappend(result, (int[]){i}, 0);
+ }
+ }
+
+ }
+ BBPkeepref((*resID = result->batCacheid));
+ BBPkeepref((*resDesc = resultDesc->batCacheid));
+ 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;
- for (int i = 0; i < subject->batCount; ++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){
- THRprintf (GDKout, "decomposing bat %d into %d and %d
bits\n",subjectBAT[0], approximationBits[0], 0);
BAT* subject = BATdescriptor(*subjectBAT);
+ if (VIEWtparent(subject))
+ subject = BATdescriptor(abs(VIEWtparent(subject)));
+ THRprintf (GDKout, "decomposing bat tail %d into %d and %d bits\n",
subject->batCacheid, approximationBits[0], Tsize(subject)*8-*approximationBits);
+ BATsetprop(subject, batRegistryIndex, TYPE_int,
(int[]){decomposeIntArray((int*)Tloc(subject, BUNfirst(subject)),
subject->batCount, *approximationBits)});
BBPkeepref(*res = BATcopy(subject, subject->htype, subject->ttype,
TRUE)->batCacheid);
return MAL_SUCCEED;
}
@@ -82,120 +208,53 @@ str BWDLeftJoinApproximate(bat * res, ba
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;
+ 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 * left, bat * right, bat * approx){
+str BWDLeftJoinRefine(bat * res, bat * l, bat * r, bat * approx){
+ ALGODEBUG THRprintf(GDKout, "#BWDfetchjoin: approximating;\n");
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list