Changeset: ab770c3b2521 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=ab770c3b2521
Modified Files:
sql/backends/monet5/UDF/capi/Tests/capi01.sql
sql/backends/monet5/UDF/capi/capi.c
Branch: jitudf
Log Message:
Treat scalar and bat input the same.
diffs (truncated from 1010 to 300 lines):
diff --git a/sql/backends/monet5/UDF/capi/Tests/capi01.sql
b/sql/backends/monet5/UDF/capi/Tests/capi01.sql
--- a/sql/backends/monet5/UDF/capi/Tests/capi01.sql
+++ b/sql/backends/monet5/UDF/capi/Tests/capi01.sql
@@ -5,8 +5,7 @@ CREATE FUNCTION capi01(inp INTEGER) RETU
language C
{
#include <math.h>
-
- size_t count = inp;
+ size_t count = inp.data[0];
i->initialize(i, count);
d->initialize(d, count);
for(size_t j = 0; j < count; j++) {
diff --git a/sql/backends/monet5/UDF/capi/capi.c
b/sql/backends/monet5/UDF/capi/capi.c
--- a/sql/backends/monet5/UDF/capi/capi.c
+++ b/sql/backends/monet5/UDF/capi/capi.c
@@ -33,7 +33,7 @@ typedef struct _mprotected_region {
void *addr;
size_t len;
- void* actual_addr;
+ void *actual_addr;
size_t actual_len;
bool is_protected;
@@ -41,7 +41,8 @@ typedef struct _mprotected_region {
struct _mprotected_region *next;
} mprotected_region;
-static char *mprotect_region(void *addr, size_t len, mprotected_region
**regions);
+static char *mprotect_region(void *addr, size_t len,
+ mprotected_region
**regions);
static char *clear_mprotect(void *addr, size_t len);
static allocated_region *allocated_regions[THREADS];
@@ -55,8 +56,8 @@ struct _cached_functions;
typedef struct _cached_functions {
jitted_function function;
BUN expression_hash;
- char* parameters;
- void* dll_handle;
+ char *parameters;
+ void *dll_handle;
struct _cached_functions *next;
} cached_functions;
@@ -65,7 +66,6 @@ typedef struct _cached_functions {
static cached_functions *function_cache[FUNCTION_CACHE_SIZE];
static MT_Lock cache_lock;
-
static str CUDFeval(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci,
bit grouped);
@@ -100,13 +100,13 @@ static bool WriteTextToFile(FILE *f, con
static void handler(int sig, siginfo_t *si, void *unused)
{
int actually_protected_area = false;
- mprotected_region* found_region = NULL;
+ mprotected_region *found_region = NULL;
int tid = THRgettid();
(void)sig;
(void)unused;
// we caught a segfault or bus error
- // this can be either because
+ // this can be either because
// (1) the function accessed a protected piece of memory
// (2) the function caused a segfault by e.g. dereferencing a NULL
pointer
// in the first case, this *might* be a valid memory access
@@ -116,13 +116,15 @@ static void handler(int sig, siginfo_t *
// was actually an error
if (actual_mprotected_regions[tid]) {
- mprotected_region* region = *actual_mprotected_regions[tid];
- while(region) {
- if (si->si_addr >= region->addr && (char*) si->si_addr
<= (char*) region->addr + region->len) {
+ mprotected_region *region = *actual_mprotected_regions[tid];
+ while (region) {
+ if (si->si_addr >= region->addr &&
+ (char *)si->si_addr <= (char *)region->addr +
region->len) {
// the address belongs to this mprotected region
found_region = region;
- if (si->si_addr >= region->actual_addr &&
- (char*) si->si_addr <= (char*)
region->actual_addr + region->actual_len) {
+ if (si->si_addr >= region->actual_addr &&
+ (char *)si->si_addr <=
+ (char *)region->actual_addr +
region->actual_len) {
// and the address is actually supposed
to be protected
actually_protected_area = true;
break;
@@ -143,12 +145,13 @@ static void handler(int sig, siginfo_t *
}
}
-static char *mprotect_region(void *addr, size_t len, mprotected_region
**regions)
+static char *mprotect_region(void *addr, size_t len,
+ mprotected_region
**regions)
{
mprotected_region *region;
int pagesize;
void *page_begin;
- void* actual_addr = addr;
+ void *actual_addr = addr;
size_t actual_len = len;
if (len == 0)
return NULL;
@@ -182,7 +185,8 @@ static char *mprotect_region(void *addr,
static char *clear_mprotect(void *addr, size_t len)
{
- if (!addr) return NULL;
+ if (!addr)
+ return NULL;
if (mprotect(addr, len, PROT_READ | PROT_WRITE) < 0) {
return strerror(errno);
@@ -213,14 +217,14 @@ static void *jump_GDK_malloc(size_t size
return ptr;
}
-static void* add_allocated_region(void* ptr)
+static void *add_allocated_region(void *ptr)
{
allocated_region *region;
int tid = THRgettid();
region = (allocated_region *)ptr;
region->next = allocated_regions[tid];
allocated_regions[tid] = region;
- return (char*)ptr + sizeof(allocated_region);
+ return (char *)ptr + sizeof(allocated_region);
}
static void *wrapped_GDK_malloc(size_t size)
@@ -274,7 +278,8 @@ GENERATE_BASE_HEADERS(cudf_data_blob, bl
}
\
inputs[index] = bat_data;
\
bat_data->is_null = tpe##_is_null;
\
- bat_data->scale = argnode ? pow(10, ((sql_arg
*)argnode->data)->type.scale) : 1; \
+ bat_data->scale =
\
+ argnode ? pow(10, ((sql_arg *)argnode->data)->type.scale) : 1;
\
bat_data->initialize = (void (*)(void *, size_t))tpe##_initialize;
#define GENERATE_BAT_INPUT(b, tpe)
\
@@ -283,26 +288,27 @@ GENERATE_BASE_HEADERS(cudf_data_blob, bl
GENERATE_BAT_INPUT_BASE(tpe);
\
bat_data->count = BATcount(b);
\
bat_data->null_value = tpe##_nil;
\
- if (b->tdense && !b->tnodense) { \
- size_t it = 0; \
- tpe val = b->T.seq; \
- /* bat is dense, materialize it */ \
- bat_data->data =
wrapped_GDK_malloc_nojump(bat_data->count * sizeof(bat_data->null_value)); \
- for(it = 0; it < bat_data->count; it++) { \
- bat_data->data[it] = val++; \
- } \
- } else { \
- bat_data->data = (tpe *)Tloc(b, 0);
\
- mprotect_retval = mprotect_region(
\
- bat_data->data, bat_data->count *
sizeof(bat_data->null_value), \
- ®ions);
\
- if (mprotect_retval) {
\
- msg = createException(MAL, "cudf.eval",
\
-
"Failed to mprotect region: %s", \
-
mprotect_retval); \
- goto wrapup;
\
- }
\
- } \
+ if (b->tdense && !b->tnodense) {
\
+ size_t it = 0;
\
+ tpe val = b->T.seq;
\
+ /* bat is dense, materialize it */
\
+ bat_data->data = wrapped_GDK_malloc_nojump(
\
+ bat_data->count *
sizeof(bat_data->null_value)); \
+ for (it = 0; it < bat_data->count; it++) {
\
+ bat_data->data[it] = val++;
\
+ }
\
+ } else {
\
+ bat_data->data = (tpe *)Tloc(b, 0);
\
+ mprotect_retval = mprotect_region(
\
+ bat_data->data,
\
+ bat_data->count * sizeof(bat_data->null_value),
®ions); \
+ if (mprotect_retval) {
\
+ msg = createException(MAL, "cudf.eval",
\
+
"Failed to mprotect region: %s", \
+
mprotect_retval); \
+ goto wrapup;
\
+ }
\
+ }
\
}
#define GENERATE_BAT_OUTPUT_BASE(tpe)
\
@@ -316,7 +322,8 @@ GENERATE_BASE_HEADERS(cudf_data_blob, bl
bat_data->count = 0;
\
bat_data->data = NULL;
\
bat_data->is_null = tpe##_is_null;
\
- bat_data->scale = argnode ? pow(10, ((sql_arg
*)argnode->data)->type.scale) : 1; \
+ bat_data->scale =
\
+ argnode ? pow(10, ((sql_arg *)argnode->data)->type.scale) : 1;
\
bat_data->initialize = (void (*)(void *, size_t))tpe##_initialize;
#define GENERATE_BAT_OUTPUT(tpe)
\
@@ -410,11 +417,11 @@ static str CUDFeval(Client cntxt, MalBlk
: (GDKgetenv(cc_flag) ? GDKgetenv(cc_flag) :
JIT_COMPILER_NAME);
const char *struct_prefix = "struct cudf_data_struct_";
- const char* funcname;
+ const char *funcname;
BUN expression_hash = 0, funcname_hash = 0;
- cached_functions* cached_function;
- char* function_parameters = NULL;
+ cached_functions *cached_function;
+ char *function_parameters = NULL;
int tid = THRgettid();
size_t input_size = 0;
bit non_grouped_aggregate = 0;
@@ -538,23 +545,25 @@ static str CUDFeval(Client cntxt, MalBlk
}
}
- function_parameters = GDKzalloc((j + input_count + output_count + 1) *
sizeof(char));
+ function_parameters =
+ GDKzalloc((j + input_count + output_count + 1) * sizeof(char));
if (!function_parameters) {
msg = createException(MAL, "cudf.eval", MAL_MALLOC_FAIL);
goto wrapup;
}
- for(i = 0; i < input_count; i++) {
+ for (i = 0; i < input_count; i++) {
if (!isaBatType(getArgType(mb, pci, i))) {
function_parameters[i] = getArgType(mb, pci, i);
} else {
function_parameters[i] = getBatType(getArgType(mb, pci,
i));
}
}
- for(i = 0; i < output_count; i++) {
+ for (i = 0; i < output_count; i++) {
if (!isaBatType(getArgType(mb, pci, i))) {
function_parameters[input_count + i] = getArgType(mb,
pci, i);
} else {
- function_parameters[input_count + i] =
getBatType(getArgType(mb, pci, i));
+ function_parameters[input_count + i] =
+ getBatType(getArgType(mb, pci, i));
}
}
j = input_count + output_count;
@@ -573,7 +582,7 @@ static str CUDFeval(Client cntxt, MalBlk
MT_lock_set(&cache_lock);
cached_function = function_cache[funcname_hash];
- while(cached_function) {
+ while (cached_function) {
if (cached_function->expression_hash == expression_hash &&
strcmp(cached_function->parameters,
function_parameters) == 0) {
// this function matches our compiled function
@@ -679,8 +688,8 @@ static str CUDFeval(Client cntxt, MalBlk
if (is_preprocessor_directive) {
// the previous line was a
preprocessor directive
// write it to the file
- ATTEMPT_TO_WRITE_DATA_TO_FILE(f,
-
exprStr + preprocessor_start,
+
ATTEMPT_TO_WRITE_DATA_TO_FILE(f, exprStr +
+
preprocessor_start,
i - preprocessor_start);
ATTEMPT_TO_WRITE_TO_FILE(f,
"\n");
for (j = preprocessor_start; j
< i; j++) {
@@ -711,35 +720,25 @@ static str CUDFeval(Client cntxt, MalBlk
}
ATTEMPT_TO_WRITE_TO_FILE(f, "\nchar* ");
ATTEMPT_TO_WRITE_TO_FILE(f, funcname);
- ATTEMPT_TO_WRITE_TO_FILE(
- f,
- "(void** __inputs, void** __outputs,
malloc_function_ptr malloc) {\n");
+ ATTEMPT_TO_WRITE_TO_FILE(f, "(void** __inputs, void**
__outputs, "
+
"malloc_function_ptr malloc) {\n");
- // now we convert the input arguments from void** to the proper
input/output
+ // now we convert the input arguments from void** to the proper
+ // input/output
// of the function
// first convert the input
for (i = pci->retc + ARG_OFFSET; i < (size_t)pci->argc; i++) {
- if (!isaBatType(getArgType(mb, pci, i))) {
- // scalar input
- int scalar_type = getArgType(mb, pci, i);
- const char *tpe =
GetTypeDefinition(scalar_type);
- assert(tpe);
- if (tpe) {
- snprintf(buf, sizeof(buf), "%s %s =
*((%s*)__inputs[%zu]);\n",
- tpe, args[i], tpe, i -
(pci->retc + ARG_OFFSET));
- ATTEMPT_TO_WRITE_TO_FILE(f, buf);
- }
- } else {
- int bat_type = getBatType(getArgType(mb, pci,
i));
- const char *tpe = GetTypeName(bat_type);
- assert(tpe);
- if (tpe) {
- snprintf(buf, sizeof(buf),
- "%s%s %s =
*((%s%s*)__inputs[%zu]);\n", struct_prefix,
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list