Skip to content

Commit

Permalink
allows to build towards PostgreSQL v16
Browse files Browse the repository at this point in the history
  • Loading branch information
kaigai committed Sep 3, 2023
1 parent b1a487b commit 8a3baef
Show file tree
Hide file tree
Showing 12 changed files with 61 additions and 43 deletions.
8 changes: 4 additions & 4 deletions src/aggfuncs.c
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ pgstrom_var_samp_final(PG_FUNCTION_ARGS)

if (fcinfo->isnull)
PG_RETURN_NULL();
PG_RETURN_NUMERIC(DirectFunctionCall1(float8_numeric, datum));
PG_RETURN_DATUM(DirectFunctionCall1(float8_numeric, datum));
}

Datum
Expand All @@ -508,7 +508,7 @@ pgstrom_var_pop_final(PG_FUNCTION_ARGS)

if (fcinfo->isnull)
PG_RETURN_NULL();
PG_RETURN_NUMERIC(DirectFunctionCall1(float8_numeric, datum));
PG_RETURN_DATUM(DirectFunctionCall1(float8_numeric, datum));
}

Datum
Expand All @@ -528,7 +528,7 @@ pgstrom_stddev_samp_final(PG_FUNCTION_ARGS)

if (fcinfo->isnull)
PG_RETURN_NULL();
PG_RETURN_NUMERIC(DirectFunctionCall1(float8_numeric, datum));
PG_RETURN_DATUM(DirectFunctionCall1(float8_numeric, datum));
}

Datum
Expand All @@ -548,7 +548,7 @@ pgstrom_stddev_pop_final(PG_FUNCTION_ARGS)

if (fcinfo->isnull)
PG_RETURN_NULL();
PG_RETURN_NUMERIC(DirectFunctionCall1(float8_numeric, datum));
PG_RETURN_DATUM(DirectFunctionCall1(float8_numeric, datum));
}

/*
Expand Down
13 changes: 7 additions & 6 deletions src/codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -1847,7 +1847,7 @@ codegen_scalar_array_op_expression(codegen_context *context,
/* 2nd arg - expression to be saved */
if (buf)
{
devtype_info *dtype_e = dtype_a->type_element;
devtype_info *__dtype_e = dtype_a->type_element;
int __off;

memset(&kexp, 0, sizeof(kexp));
Expand All @@ -1860,14 +1860,15 @@ codegen_scalar_array_op_expression(codegen_context *context,
offsetof(kern_expression, u.data));

/* 1st arg of the 2nd arg (comparator function) */
__dtype_e = dtype_a->type_element;
memset(&kexp, 0, sizeof(kexp));
kexp.exptype = dtype_e->type_code;
kexp.exptype = __dtype_e->type_code;
kexp.expflags = context->kexp_flags;
kexp.opcode = FuncOpCode__VarExpr;
kexp.nr_args = 0;
kexp.u.v.var_typlen = dtype_e->type_length;
kexp.u.v.var_typbyval = dtype_e->type_byval;
kexp.u.v.var_typalign = dtype_e->type_align;
kexp.u.v.var_typlen = __dtype_e->type_length;
kexp.u.v.var_typbyval = __dtype_e->type_byval;
kexp.u.v.var_typalign = __dtype_e->type_align;
kexp.u.v.var_slot_id = slot_id;
__off = __appendBinaryStringInfo(buf, &kexp, SizeOfKernExprVar);
__appendKernExpMagicAndLength(buf, __off);
Expand Down Expand Up @@ -3775,7 +3776,7 @@ __xpucode_to_cstring(StringInfo buf,
const char *func_name = NULL;
const char *rettype_name = NULL;

for (int i=0; devonly_funcs_catalog[i].func_code; i++)
for (i=0; devonly_funcs_catalog[i].func_code; i++)
{
if (devonly_funcs_catalog[i].func_code == kexp->opcode)
{
Expand Down
2 changes: 1 addition & 1 deletion src/dpu_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ GetOptimalDpuForRelation(Relation relation, const char **p_dpu_pathname)
{
const DpuStorageEntry *ds_entry;
SMgrRelation smgr = RelationGetSmgr(relation);
char *rel_pathname = relpath(smgr->smgr_rnode, MAIN_FORKNUM);
char *rel_pathname = smgr_relpath(smgr, MAIN_FORKNUM);
const char *dpu_pathname;

ds_entry = GetOptimalDpuForFile(rel_pathname, &dpu_pathname);
Expand Down
6 changes: 2 additions & 4 deletions src/executor.c
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,7 @@ __build_session_param_info(pgstromTaskState *pts,
{
struct varlena *temp = PG_DETOAST_DATUM(param_value);

offset = __appendBinaryStringInfo(buf,
DatumGetPointer(temp),
VARSIZE(temp));
offset = __appendBinaryStringInfo(buf, temp, VARSIZE(temp));
if (param_value != PointerGetDatum(temp))
pfree(temp);
}
Expand Down Expand Up @@ -1092,7 +1090,7 @@ pgstromExecInitTaskState(CustomScanState *node, EState *estate, int eflags)
{
SMgrRelation smgr = RelationGetSmgr(rel);
Oid am_oid = RelationGetForm(rel)->relam;
const char *kds_pathname = relpath(smgr->smgr_rnode, MAIN_FORKNUM);
const char *kds_pathname = smgr_relpath(smgr, MAIN_FORKNUM);

if (am_oid != HEAP_TABLE_AM_OID)
elog(ERROR, "PG-Strom does not support table access method: %s",
Expand Down
2 changes: 1 addition & 1 deletion src/extra.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ pgstrom_license_query(PG_FUNCTION_ARGS)
if (!license)
PG_RETURN_NULL();

PG_RETURN_POINTER(DirectFunctionCall1(json_in, PointerGetDatum(license)));
PG_RETURN_DATUM(DirectFunctionCall1(json_in, PointerGetDatum(license)));
}

/*
Expand Down
2 changes: 1 addition & 1 deletion src/gpu_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -780,8 +780,8 @@ __setup_kern_data_store_column(kern_data_store *kds_head,
for (int j=0; j < tupdesc->natts; j++)
{
Form_pg_attribute attr = TupleDescAttr(tupdesc, j);
kern_colmeta *cmeta = &kds_head->colmeta[j];

cmeta = &kds_head->colmeta[j];
if (!attr->attnotnull)
{
sz = MAXALIGN(BITMAPLEN(nrooms));
Expand Down
3 changes: 1 addition & 2 deletions src/gpu_scan.c
Original file line number Diff line number Diff line change
Expand Up @@ -640,8 +640,7 @@ __build_explain_tlist_junks(PlannerInfo *root,
0);
foreach (lc, context->tlist_dev)
{
TargetEntry *tle = lfirst(lc);

tle = lfirst(lc);
if (equal(tle->expr, var))
break;
}
Expand Down
24 changes: 15 additions & 9 deletions src/gpu_service.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,14 @@ static bool __gpuserv_debug_output_dummy;
if (gpuserv_shared_state && \
pg_atomic_read_u32(&gpuserv_shared_state->gpuserv_debug_output) != 0) \
{ \
const char *filename = __FILE__; \
for (const char *pos = filename; *pos != '\0'; pos++) \
const char *__fname = __FILE__; \
for (const char *__pos = __fname; *__pos != '\0'; __pos++) \
{ \
if (pos[0] == '/' && pos[1] != '\0') \
filename = pos + 1; \
if (__pos[0] == '/' && __pos[1] != '\0') \
__fname = __pos + 1; \
} \
fprintf(stderr, "GpuServ: " fmt " (%s:%d)\n", \
##__VA_ARGS__, filename, __LINE__); \
##__VA_ARGS__, __fname, __LINE__); \
} \
} while(0)

Expand Down Expand Up @@ -1159,6 +1159,13 @@ gpuClientWriteBack(gpuClient *gclient,
*
* ----------------------------------------------------------------
*/
static void
__gpuClientELog(gpuClient *gclient,
int errcode,
const char *filename, int lineno,
const char *funcname,
const char *fmt, ...) pg_attribute_printf(6,7);

#define gpuClientELog(gclient,fmt,...) \
__gpuClientELog((gclient), ERRCODE_DEVICE_INTERNAL, \
__FILE__, __LINE__, __FUNCTION__, \
Expand Down Expand Up @@ -1244,7 +1251,7 @@ __resolveDevicePointersWalker(gpuContext *gcontext,
xpu_function_catalog_entry *xpu_func;
xpu_type_catalog_entry *xpu_type;
kern_expression *karg;
int i;
int i;

/* lookup device function */
xpu_func = hash_search(gcontext->cuda_func_htab,
Expand Down Expand Up @@ -1349,7 +1356,6 @@ __resolveDevicePointers(gpuContext *gcontext,
if (encode)
{
xpu_encode_info *catalog = gcontext->cuda_encode_catalog;
int i;

for (i=0; ; i++)
{
Expand Down Expand Up @@ -1570,10 +1576,10 @@ gpuservHandleGpuTaskExec(gpuClient *gclient, XpuCommand *xcmd)
if (!gc_lmap)
{
gpuClientELog(gclient, "no GpuCache (dat=%u,rel=%u,sig=%09lx) found - %s",
errbuf,
ident->database_oid,
ident->table_oid,
ident->signature);
ident->signature,
errbuf);
return;
}
}
Expand Down
17 changes: 9 additions & 8 deletions src/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1213,7 +1213,8 @@ pgstrom_random_text_length(PG_FUNCTION_ARGS)
PG_FUNCTION_INFO_V1(pgstrom_random_text_length);

static Datum
simple_make_range(TypeCacheEntry *typcache, Datum x_val, Datum y_val)
simple_make_range(PG_FUNCTION_ARGS,
TypeCacheEntry *typcache, Datum x_val, Datum y_val)
{
RangeBound x, y;
RangeType *range;
Expand All @@ -1230,8 +1231,8 @@ simple_make_range(TypeCacheEntry *typcache, Datum x_val, Datum y_val)
y.inclusive = generate_null(25.0);
y.lower = false;

range = make_range(typcache, &x, &y, false);

range = make_range(typcache, &x, &y, false,
fcinfo->context);
return PointerGetDatum(range);
}

Expand All @@ -1256,7 +1257,7 @@ pgstrom_random_int4range(PG_FUNCTION_ARGS)
typcache = range_get_typcache(fcinfo, type_oid);
x = lower + __random() % (upper - lower);
y = lower + __random() % (upper - lower);
return simple_make_range(typcache,
return simple_make_range(fcinfo, typcache,
Int32GetDatum(Min(x,y)),
Int32GetDatum(Max(x,y)));
}
Expand Down Expand Up @@ -1285,7 +1286,7 @@ pgstrom_random_int8range(PG_FUNCTION_ARGS)
x = lower + v % (upper - lower);
v = (__random() << 31) | __random();
y = lower + v % (upper - lower);
return simple_make_range(typcache,
return simple_make_range(fcinfo, typcache,
Int64GetDatum(Min(x,y)),
Int64GetDatum(Max(x,y)));
}
Expand Down Expand Up @@ -1337,7 +1338,7 @@ pgstrom_random_tsrange(PG_FUNCTION_ARGS)
x = lower + v % (upper - lower);
v = (__random() << 31) | __random();
y = lower + v % (upper - lower);
return simple_make_range(typcache,
return simple_make_range(fcinfo, typcache,
TimestampGetDatum(Min(x,y)),
TimestampGetDatum(Max(x,y)));
}
Expand Down Expand Up @@ -1389,7 +1390,7 @@ pgstrom_random_tstzrange(PG_FUNCTION_ARGS)
x = lower + v % (upper - lower);
v = (__random() << 31) | __random();
y = lower + v % (upper - lower);
return simple_make_range(typcache,
return simple_make_range(fcinfo, typcache,
TimestampTzGetDatum(Min(x,y)),
TimestampTzGetDatum(Max(x,y)));
}
Expand Down Expand Up @@ -1427,7 +1428,7 @@ pgstrom_random_daterange(PG_FUNCTION_ARGS)
typcache = range_get_typcache(fcinfo, type_oid);
x = lower + __random() % (upper - lower);
y = lower + __random() % (upper - lower);
return simple_make_range(typcache,
return simple_make_range(fcinfo, typcache,
DateADTGetDatum(Min(x,y)),
DateADTGetDatum(Max(x,y)));
}
Expand Down
1 change: 1 addition & 0 deletions src/pg_strom.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@
#include "xpu_common.h"
#include "cuda_common.h"
#include "pg_utils.h"
#include "pg_compat.h"
#include "heterodb_extra.h"

/* ------------------------------------------------
Expand Down
8 changes: 5 additions & 3 deletions src/relscan.c
Original file line number Diff line number Diff line change
Expand Up @@ -591,8 +591,10 @@ pgstromRelScanChunkDirect(pgstromTaskState *pts,
pgstromSharedState *ps_state = pts->ps_state;
Relation relation = pts->css.ss.ss_currentRelation;
HeapScanDesc h_scan = (HeapScanDesc)pts->css.ss.ss_currentScanDesc;
/* NOTE: 'smgr_rnode' always locates on the head of SMgrRelationData */
RelFileNodeBackend *smgr_rnode = (RelFileNodeBackend *)RelationGetSmgr(relation);
SMgrRelation smgr = RelationGetSmgr(relation);

// /* NOTE: 'smgr_rnode' always locates on the head of SMgrRelationData */
// RelFileNodeBackend *smgr_rnode = (RelFileNodeBackend *)RelationGetSmgr(relation);
XpuCommand *xcmd;
kern_data_store *kds;
unsigned long m_offset = 0UL;
Expand Down Expand Up @@ -642,7 +644,7 @@ pgstromRelScanChunkDirect(pgstromTaskState *pts,
LWLock *bufLock;
int buf_id;

INIT_BUFFERTAG(bufTag, smgr_rnode->node, MAIN_FORKNUM, block_num);
smgr_init_buffer_tag(&bufTag, smgr, MAIN_FORKNUM, block_num);
bufHash = BufTableHashCode(&bufTag);
bufLock = BufMappingPartitionLock(bufHash);

Expand Down
18 changes: 14 additions & 4 deletions src/xpu_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,19 @@
/*
* Several fundamental data types and macros
*/
#ifndef POSTGRES_H
#ifndef Assert
#define Assert(cond) assert(cond)
#endif
#ifndef Max
#define Max(a,b) ((a) > (b) ? (a) : (b))
#endif
#ifndef Min
#define Min(a,b) ((a) < (b) ? (a) : (b))
#endif
#ifndef Abs
#define Abs(x) ((x) >= 0 ? (x) : -(x))
#endif
#ifndef POSTGRES_H
typedef uint64_t Datum;
typedef unsigned int Oid;

Expand Down Expand Up @@ -905,7 +914,8 @@ typedef uint16_t OffsetNumber;
((OffsetNumber) (-1 + (offsetNumber)))

/* definitions in storage/bufpage.h */
typedef struct PageHeaderData
typedef char *Page;
typedef struct PageHeaderData
{
#if 0
/*
Expand Down Expand Up @@ -1175,7 +1185,7 @@ KDS_BLOCK_REF_HTUP(kern_data_store *kds,
pg_page = KDS_BLOCK_PGPAGE(kds, block_id);

Assert(lpp >= pg_page->pd_linp &&
lpp - pg_page->pd_linp < PageGetMaxOffsetNumber(pg_page));
lpp - pg_page->pd_linp < PageGetMaxOffsetNumber((Page)pg_page));
if (p_self)
{
p_self->ip_blkid.bi_hi = block_nr >> 16;
Expand All @@ -1184,7 +1194,7 @@ KDS_BLOCK_REF_HTUP(kern_data_store *kds,
}
if (p_len)
*p_len = ItemIdGetLength(lpp);
return (HeapTupleHeaderData *)PageGetItem(pg_page, lpp);
return (HeapTupleHeaderData *)PageGetItem((Page)pg_page, lpp);
}

INLINE_FUNCTION(bool)
Expand Down

0 comments on commit 8a3baef

Please sign in to comment.