From 5549706443f70ab6dd57421006c09b4fd03d16f5 Mon Sep 17 00:00:00 2001 From: Bill Date: Sun, 23 Oct 2022 05:47:53 +0800 Subject: [PATCH] fixed issue for user module --- .gitignore | 1 + Makefile | 5 +++-- reconstruct/ast.py | 6 +++--- sdk/Makefile | 8 +++++++- sdk/irf.cpp | 33 +++++++++++++++++++++++---------- server/table.h | 17 ++++++++++++++++- server/vector_type.hpp | 3 +++ tests/dt.a | 40 ++++++++++++++++++++-------------------- tests/dt2.a | 36 ++++++++++++++++-------------------- tests/q1.sql | 2 -- 10 files changed, 92 insertions(+), 59 deletions(-) diff --git a/.gitignore b/.gitignore index 644be8b..508685f 100644 --- a/.gitignore +++ b/.gitignore @@ -51,6 +51,7 @@ k **/Debug **/Release test*.c* +data/benchmark *.csv !test.csv !test2.csv diff --git a/Makefile b/Makefile index dd7747e..1707240 100644 --- a/Makefile +++ b/Makefile @@ -4,11 +4,12 @@ MonetDB_INC = Threading = CXXFLAGS = --std=c++1z ifeq ($(AQ_DEBUG), 1) - OPTFLAGS = -g3 + OPTFLAGS = -g3 -fsanitize=address -fsanitize=leak + LINKFLAGS = else OPTFLAGS = -O3 -DNDEBUG -fno-stack-protector + LINKFLAGS = -flto endif -LINKFLAGS = -flto # + $(AQ_LINK_FLAG) SHAREDFLAGS = -shared FPIC = -fPIC COMPILER = $(shell $(CXX) --version | grep -q clang && echo clang|| echo gcc) diff --git a/reconstruct/ast.py b/reconstruct/ast.py index d82ebce..173399b 100644 --- a/reconstruct/ast.py +++ b/reconstruct/ast.py @@ -343,7 +343,7 @@ class projection(ast_node): ) else: # for funcs evaluate f_i(x, ...) - self.context.emitc(f'{self.out_table.contextname_cpp}->get_col<{key}>() = {val[1]};') + self.context.emitc(f'{self.out_table.contextname_cpp}->get_col<{key}>().initfrom({val[1]}, "{cols[i].name}");') # print out col_is if 'into' not in node: self.context.emitc(f'print(*{self.out_table.contextname_cpp});') @@ -990,7 +990,7 @@ class load(ast_node): self.context.queries.append(f'F{fname}') ret_type = VoidT if 'ret_type' in f: - ret_type = Types.decode(f['ret_type']) + ret_type = Types.decode(f['ret_type'], vector_type='vector_type') nargs = 0 arglist = '' if 'vars' in f: @@ -1000,7 +1000,7 @@ class load(ast_node): nargs = len(arglist) arglist = ', '.join(arglist) # create c++ stub - cpp_stub = f'{ret_type.cname} (*{fname})({arglist}) = nullptr;' + cpp_stub = f'{"vectortype_cstorage" if isinstance(ret_type, VectorT) else ret_type.cname} (*{fname})({arglist}) = nullptr;' self.context.module_stubs += cpp_stub + '\n' self.context.module_map[fname] = cpp_stub #registration for parser diff --git a/sdk/Makefile b/sdk/Makefile index 7bd5c8c..b146a81 100644 --- a/sdk/Makefile +++ b/sdk/Makefile @@ -1,5 +1,11 @@ +OPT_FLASG = +ifneq ($(DEBUG), 1) + OPT_FLAGS = -Ofast -march=native -flto -DNDEBUG +else + OPT_FLAGS = -g3 -D_DEBUG -fsanitize=leak -fsanitize=address +endif example: $(CXX) -shared -fPIC example.cpp aquery_mem.cpp -fno-semantic-interposition -Ofast -march=native -flto --std=c++1z -o ../test.so irf: - $(CXX) -shared -fPIC RF.cpp irf.cpp incrementalDecisionTree.cpp aquery_mem.cpp Evaluation.cpp -fno-semantic-interposition -Ofast -march=native -flto --std=c++1z -o ../libirf.so + $(CXX) -shared -fPIC RF.cpp irf.cpp incrementalDecisionTree.cpp aquery_mem.cpp Evaluation.cpp -fno-semantic-interposition $(OPT_FLAGS) --std=c++1z -o ../libirf.so all: example diff --git a/sdk/irf.cpp b/sdk/irf.cpp index 8433c95..36cf4c2 100644 --- a/sdk/irf.cpp +++ b/sdk/irf.cpp @@ -36,19 +36,32 @@ __AQEXPORT__(bool) additem(ColRefX, long y, long size){ pt ++; return 1; } -__AQEXPORT__(bool) fit(){ - if(pt<=0)return 0; - dt->fit(data, result, pt); - return 1; +__AQEXPORT__(bool) fit(vector_type> v, vector_type res){ + double** data = (double**)malloc(v.size*sizeof(double*)); + for(int i = 0; i < v.size; ++i) + data[i] = v.container[i].container; + dt->fit(data, res.container, v.size); + return true; } -__AQEXPORT__(ColRef_storage) predict(){ - int* result = (int*)malloc(pt*sizeof(int)); - for(long i=0; iTest(data[i], dt->DTree); - } +__AQEXPORT__(vectortype_cstorage) predict(vector_type> v){ + int* result = (int*)malloc(v.size*sizeof(int)); - return ColRef_storage(new ColRef_storage(result, pt, 0, "prediction", 0), 1, 0, "prediction", 0); + for(long i=0; iTest(v.container[i].container, dt->DTree); + //printf("%d ", result[i]); + } + auto container = (vector_type*)malloc(sizeof(vector_type)); + container->size = v.size; + container->capacity = 0; + container->container = result; + // container->out(10); + // ColRef>* col = (ColRef>*)malloc(sizeof(ColRef>)); + auto ret = vectortype_cstorage{.container = container, .size = 1, .capacity = 0}; + // col->initfrom(ret, "sibal"); + // print(*col); + return ret; + //return true; } diff --git a/server/table.h b/server/table.h index 56c7a4b..f3911af 100644 --- a/server/table.h +++ b/server/table.h @@ -74,7 +74,7 @@ public: this->container = (_Ty*)container; this->name = name; } - template