Changeset: fb8e1196ca0c for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=fb8e1196ca0c
Added Files:
        MonetDB5/modules/mal/manifold.c
Modified Files:
        MonetDB5/mal/mal.c
        MonetDB5/mal/mal.h
        MonetDB5/modules/mal/mdb.c
        MonetDB5/optimizer/opt_projectionpath.c
        gdk/gdk.h
        tools/mserver/mserver5.c
Branch: gdk-tracer
Log Message:

Removed OPTdebug


diffs (truncated from 620 to 300 lines):

diff --git a/MonetDB5/mal/mal.c b/MonetDB5/mal/mal.c
--- a/MonetDB5/mal/mal.c
+++ b/MonetDB5/mal/mal.c
@@ -19,10 +19,6 @@ stream *maleventstream = 0;
 /* The compile time debugging flags are turned into bit masks, akin to GDK */
 lng MALdebug;
 
-/* CHECK */
-// Remove?
-lng OPTdebug;
-
 #ifdef HAVE_HGE
 int have_hge;
 #endif
diff --git a/MonetDB5/mal/mal.h b/MonetDB5/mal/mal.h
--- a/MonetDB5/mal/mal.h
+++ b/MonetDB5/mal/mal.h
@@ -38,49 +38,6 @@
  */
 #define MAXSCRIPT 64
 
-/* The compile time debugging flags are turned into bit masks, akin to GDK */
-/* CHECK */
-// Remove?
-mal_export lng OPTdebug;
-
-/* CHECK */
-// Remove?
-#define OPTaliases                     (1 )
-#define OPTcandidates          ((lng)1 << 1)
-#define OPTcoercion                    ((lng)1 << 2)
-#define OPTcommonterms         ((lng)1 << 3)
-#define OPTconstants           ((lng)1 << 4)
-#define OPTcostmodel           ((lng)1 << 5)
-#define OPTdataflow                    ((lng)1 << 6)
-#define OPTdeadcode                    ((lng)1 << 7)
-#define OPTemptybind           ((lng)1 << 8)
-#define OPTevaluate                    ((lng)1 << 9)
-#define OPTgarbagecollector    ((lng)1 << 10)
-#define OPTgenerator           ((lng)1 << 11)
-#define OPTinline                      ((lng)1 << 12)
-#define OPTjit                         ((lng)1 << 13)
-#define OPTjson                                ((lng)1 << 14)
-#define OPTmacros                      ((lng)1 << 15)
-#define OPTmatpack                     ((lng)1 << 15)
-#define OPTmergetable          ((lng)1 << 16)
-#define OPTmitosis                     ((lng)1 << 17)
-#define OPTmultiplex           ((lng)1 << 18)
-#define OPToltp                                ((lng)1 << 19)
-#define OPTpipes                       ((lng)1 << 20)
-#define OPTpostfix                     ((lng)1 << 21)
-#define OPTprelude                     ((lng)1 << 22)
-#define OPTprofiler                    ((lng)1 << 23)
-#define OPTprojectionpath      ((lng)1 << 24)
-#define OPTpushselect          ((lng)1 << 25)
-#define OPTquerylog                    ((lng)1 << 26)
-#define OPTreduce                      ((lng)1 << 27)
-#define OPTremap                       ((lng)1 << 28)
-#define OPTremotequeries       ((lng)1 << 29)
-#define OPTreorder                     ((lng)1 << 30)
-#define OPTsupport                     ((lng)1 << 31)
-#define OPTvolcano                     ((lng)1 << 32)
-#define OPTwlc                         ((lng)1 << 33)
-
 mal_export lng MALdebug;
 
 /*
@@ -113,7 +70,6 @@ mal_export int have_hge;
 #define GRPmodules (LOADMASK)
 #define GRPalgorithms (ALGOMASK | ESTIMASK)
 #define GRPperformance (DEADBEEFMASK)
-#define GRPoptimizers  (OPTMASK)
 #define GRPforcemito (FORCEMITOMASK | NOSYNCMASK)
 
 mal_export MT_Lock  mal_contextLock;
diff --git a/MonetDB5/modules/mal/manifold.c b/MonetDB5/modules/mal/manifold.c
new file mode 100644
--- /dev/null
+++ b/MonetDB5/modules/mal/manifold.c
@@ -0,0 +1,373 @@
+/*
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0.  If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * Copyright 1997 - July 2008 CWI, August 2008 - 2019 MonetDB B.V.
+ */
+
+/*
+ * M.L. Kersten
+ */
+#include "monetdb_config.h"
+#include "manifold.h"
+#include "mal_resolve.h"
+#include "mal_builder.h"
+#include "gdk_tracer.h"
+
+/* The default iterator over known scalar commands.
+ * It can be less efficient then the vector based implementations,
+ * but saves quite some hacking in non-essential cases or
+ * expensive user defined functions.
+ *
+ * To keep things simple and reasonably performant we limit the
+ * implementation to those cases where a single BAT is returned.
+ * Arguments may be of any type. The MAL signature should be a COMMAND.
+ *
+ * The functionality has been extended to also perform the manifold
+ * over aligned BATs, provided the underlying scalar function carries
+ * the 'manifold' property.
+ */
+
+typedef struct{
+       BAT *b;
+       void *first;
+       void *last;
+       int     size;
+       int type;
+       BUN cnt;
+       BATiter bi;
+       BUN  o;
+       BUN  q;
+       str *s;
+} MULTIarg;
+
+typedef struct{
+       Client cntxt;
+       MalBlkPtr mb;
+       MalStkPtr stk;
+       InstrPtr pci;
+       int fvar,lvar;
+       MULTIarg *args;
+} MULTItask;
+
+
+// Loop through the first BAT
+// keep the last error message received
+#define ManifoldLoop(Type, ...)                                                
                                        \
+       do {                                                                    
                                                        \
+               Type *v = (Type*) mut->args[0].first;                           
                        \
+               for (;;) {                                                      
                                                        \
+                       msg = (*mut->pci->fcn)(v, __VA_ARGS__);                 
                        \
+                       if (msg) break;                                         
                                                \
+                       if (++oo == olimit)                                     
                                                \
+                               break;                                          
                                                        \
+                       for( i = mut->fvar; i<= mut->lvar; i++) {               
                        \
+                               if(ATOMstorage(mut->args[i].type) == TYPE_void 
){               \
+                                       args[i] = (void*)  &mut->args[i].o;     
                                \
+                                       mut->args[i].o++;                       
                                                \
+                               } else if(mut->args[i].size == 0) {             
                                \
+                                       ;                                       
                                                                \
+                               } else if(ATOMstorage(mut->args[i].type) < 
TYPE_str ) { \
+                                       args[i] += mut->args[i].size;           
                                \
+                               } else if (ATOMvarsized(mut->args[i].type)) {   
                \
+                                       mut->args[i].o++;                       
                                                \
+                                       mut->args[i].s = (str *) 
BUNtail(mut->args[i].bi, mut->args[i].o); \
+                                       args[i] = (void*)  &mut->args[i].s;     
                                \
+                               } else {                                        
                                                        \
+                                       mut->args[i].o++;                       
                                                \
+                                       mut->args[i].s = (str *) 
Tloc(mut->args[i].b, mut->args[i].o); \
+                                       args[i] = (void*)  &mut->args[i].s;     
                                \
+                               }                                               
                                                                \
+                       }                                                       
                                                                \
+                       v++;                                                    
                                                        \
+               }                                                               
                                                                \
+       } while (0)
+
+// The target BAT tail type determines the result variable
+#ifdef HAVE_HGE
+#define Manifoldbody_hge(...)                                  \
+       case TYPE_hge: ManifoldLoop(hge,__VA_ARGS__); break
+#else
+#define Manifoldbody_hge(...)
+#endif
+#define Manifoldbody(...)                                                      
                                        \
+       do {                                                                    
                                                        \
+               switch(ATOMstorage(mut->args[0].b->ttype)){                     
                        \
+               case TYPE_bte: ManifoldLoop(bte,__VA_ARGS__); break;            
        \
+               case TYPE_sht: ManifoldLoop(sht,__VA_ARGS__); break;            
        \
+               case TYPE_int: ManifoldLoop(int,__VA_ARGS__); break;            
        \
+               case TYPE_lng: ManifoldLoop(lng,__VA_ARGS__); break;            
        \
+               Manifoldbody_hge(__VA_ARGS__);                                  
                                \
+               case TYPE_oid: ManifoldLoop(oid,__VA_ARGS__); break;            
        \
+               case TYPE_flt: ManifoldLoop(flt,__VA_ARGS__); break;            
        \
+               case TYPE_dbl: ManifoldLoop(dbl,__VA_ARGS__); break;            
        \
+               case TYPE_str:                                                  
                                                \
+               default: {                                                      
                                                        \
+                       for (;;) {                                              
                                                        \
+                               msg = (*mut->pci->fcn)(&y, __VA_ARGS__);        
                        \
+                               if (msg)                                        
                                                        \
+                                       break;                                  
                                                        \
+                               bunfastapp(mut->args[0].b, (void*) y);          
                        \
+                               GDKfree(y); y = NULL;                           
                                        \
+                               if (++oo == olimit)                             
                                                \
+                                       break;                                  
                                                        \
+                               for( i = mut->fvar; i<= mut->lvar; i++) {       
                        \
+                                       if(ATOMstorage(mut->args[i].type) == 
TYPE_void ){       \
+                                               args[i] = (void*)  
&mut->args[i].o;                             \
+                                               mut->args[i].o++;               
                                                \
+                                       } else if(mut->args[i].size == 0) {     
                                \
+                                               ;                               
                                                                \
+                                       } else if 
(ATOMstorage(mut->args[i].type) < TYPE_str){ \
+                                               args[i] += mut->args[i].size;   
                                \
+                                       } else 
if(ATOMvarsized(mut->args[i].type)){                     \
+                                               mut->args[i].o++;               
                                                \
+                                               mut->args[i].s = (str*) 
BUNtail(mut->args[i].bi, mut->args[i].o); \
+                                               args[i] =  (void*) & 
mut->args[i].s;                    \
+                                       } else {                                
                                                        \
+                                               mut->args[i].o++;               
                                                \
+                                               mut->args[i].s = (str*) 
Tloc(mut->args[i].b, mut->args[i].o); \
+                                               args[i] =  (void*) & 
mut->args[i].s;                    \
+                                       }                                       
                                                                \
+                               }                                               
                                                                \
+                       }                                                       
                                                                \
+                       break;                                                  
                                                        \
+               }                                                               
                                                                \
+               }                                                               
                                                                \
+               mut->args[0].b->theap.dirty = true;                             
                                \
+       } while (0)
+
+// single argument is preparatory step for GDK_mapreduce
+// Only the last error message is returned, the value of
+// an erroneous call depends on the operator itself.
+static str
+MANIFOLDjob(MULTItask *mut)
+{      int i;
+       char **args;
+       str y = NULL, msg= MAL_SUCCEED;
+       oid oo = 0, olimit = mut->args[mut->fvar].cnt;
+
+       if (olimit == 0)
+               return msg;                             /* nothing to do */
+
+       args = (char**) GDKzalloc(sizeof(char*) * mut->pci->argc);
+       if( args == NULL)
+               throw(MAL,"mal.manifold", SQLSTATE(HY001) MAL_MALLOC_FAIL);
+       
+       // the mod.fcn arguments are ignored from the call
+       for( i = mut->pci->retc+2; i< mut->pci->argc; i++) {
+               if ( mut->args[i].b ){
+                       if(ATOMstorage(mut->args[i].type) < TYPE_str){  
+                               args[i] = (char*) mut->args[i].first;
+                       } else if(ATOMvarsized(mut->args[i].type)){     
+                               mut->args[i].s = (str*) 
BUNtail(mut->args[i].bi, mut->args[i].o);
+                               args[i] =  (void*) & mut->args[i].s; 
+                       } else {
+                               mut->args[i].s = (str*) Tloc(mut->args[i].b, 
mut->args[i].o);
+                               args[i] =  (void*) & mut->args[i].s; 
+                       }
+               } else {
+                       args[i] = (char *) getArgReference(mut->stk,mut->pci,i);
+               }
+       }
+
+       DEBUG(MAL_MANIFOLD, "fvar %d lvar %d type %d\n", mut->fvar,mut->lvar, 
ATOMstorage(mut->args[mut->fvar].b->ttype));
+
+       // use limited argument list expansion.
+       switch(mut->pci->argc){
+       case 4: Manifoldbody(args[3]); break;
+       case 5: Manifoldbody(args[3],args[4]); break;
+       case 6: Manifoldbody(args[3],args[4],args[5]); break;
+       case 7: Manifoldbody(args[3],args[4],args[5],args[6]); break;
+       case 8: Manifoldbody(args[3],args[4],args[5],args[6],args[7]); break;
+       default:
+               msg= createException(MAL,"mal.manifold","manifold call 
limitation ");
+       }
+       if (ATOMextern(mut->args[0].type) && y) 
+               GDKfree(y); 
+bunins_failed:
+       GDKfree(args);
+       return msg;
+}
+
+/* The manifold optimizer should check for the possibility
+ * to use this implementation instead of the MAL loop.
+ */
+MALfcn
+MANIFOLDtypecheck(Client cntxt, MalBlkPtr mb, InstrPtr pci, int checkprops){
+       int i, k, tpe= 0;
+       InstrPtr q=0;
+       MalBlkPtr nmb;
+       MALfcn fcn;
+
+       if (pci->retc >1 || pci->argc > 8 || getModuleId(pci) == NULL) // 
limitation on MANIFOLDjob
+               return NULL;
+       // We need a private MAL context to resolve the function call
+       nmb = newMalBlk(2 );
+       if( nmb == NULL)
+               return NULL;
+       // the scalar function
+       q = newStmt(nmb,
+               getVarConstant(mb,getArg(pci,pci->retc)).val.sval,
+               getVarConstant(mb,getArg(pci,pci->retc+1)).val.sval);
+
+       // Prepare the single result variable
+       tpe =getBatType(getArgType(mb,pci,0));
+       k= getArg(q,0);
+       setVarType(nmb,k,tpe);
+       if ( isVarFixed(nmb,k)) 
+               setVarFixed(nmb,k);
+       if (isVarUDFtype(nmb,k))
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to