Changeset: 9ff49760a679 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=9ff49760a679
Added Files:
        geom/monetdb5/32_gpu.mal
        geom/monetdb5/gpu.c
        geom/monetdb5/gpu.h
        geom/monetdb5/gpu.mal
        geom/sql/42_gpu.sql
Modified Files:
        geom/monetdb5/Makefile.ag
        geom/sql/Makefile.ag
Branch: sfcgal
Log Message:

Add structure for the first GPU operator, G_Contains


diffs (248 lines):

diff --git a/geom/monetdb5/32_gpu.mal b/geom/monetdb5/32_gpu.mal
new file mode 100644
--- /dev/null
+++ b/geom/monetdb5/32_gpu.mal
@@ -0,0 +1,8 @@
+# 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 - 2016 MonetDB B.V.
+
+# This loads the SFCGAL module
+include gpu;
diff --git a/geom/monetdb5/Makefile.ag b/geom/monetdb5/Makefile.ag
--- a/geom/monetdb5/Makefile.ag
+++ b/geom/monetdb5/Makefile.ag
@@ -12,7 +12,7 @@ INCLUDES = ../lib \
            ../../common/options \
            ../../monetdb5/mal \
            $(GEOS_INCS) $(PROJ_INCS) \
-           $(SFCGAL_INCS)
+           $(SFCGAL_INCS) ${GPU_INCS}
 
 lib__geom = {
        MODULE
@@ -63,4 +63,30 @@ headers_autoload_sfcgal = {
        SOURCES = 31_sfcgal.mal
 }
 
-EXTRA_DIST = 30_geom.mal 31_sfcgal.mal geom.mal sfcgal.mal
+lib__gpu = {
+       #COND = HAVE_GPU
+       MODULE
+       DIR = libdir/monetdb5
+       SOURCES = gpu.h gpu.c
+       LIBS = ../lib/libgeom \
+                  ../../gdk/libbat \
+              ../../common/stream/libstream \
+              ../../monetdb5/tools/libmonetdb5 \
+              $(GPU_LIBS)
+}
+
+headers_mal_gpu = {
+       #COND = HAVE_GPU
+       HEADERS = mal
+       DIR = libdir/monetdb5
+       SOURCES = gpu.mal
+}
+
+headers_autoload_gpu = {
+       #COND = HAVE_GPU
+       HEADERS = mal
+       DIR = libdir/monetdb5/autoload
+       SOURCES = 32_gpu.mal
+}
+
+EXTRA_DIST = 30_geom.mal 31_sfcgal.mal 32_gpu.mal geom.mal sfcgal.mal gpu.mal
diff --git a/geom/monetdb5/gpu.c b/geom/monetdb5/gpu.c
new file mode 100644
--- /dev/null
+++ b/geom/monetdb5/gpu.c
@@ -0,0 +1,105 @@
+/*
+ * 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 - 2016 MonetDB B.V.
+ */
+
+/*
+ * @a Romulo Goncalves
+ * @* The simple geom module
+ */
+
+#include "gpu.h"
+
+static str
+GpnpolyWithHoles(bat *out, int nvert, dbl *vx, dbl *vy, int nholes, dbl **hx, 
dbl **hy, int *hn, bat *point_x, bat *point_y)
+{
+       BAT *bo = NULL, *bpx = NULL, *bpy;
+       dbl *px = NULL, *py = NULL;
+       BUN i = 0, cnt = 0;
+       bit *cs = NULL;
+#ifdef GEOMBULK_DEBUG
+    static struct timeval start, stop;
+    unsigned long long t;
+#endif
+
+       /*Get the BATs */
+       if ((bpx = BATdescriptor(*point_x)) == NULL) {
+               throw(MAL, "geom.point", RUNTIME_OBJECT_MISSING);
+       }
+       if ((bpy = BATdescriptor(*point_y)) == NULL) {
+               BBPunfix(bpx->batCacheid);
+               throw(MAL, "geom.point", RUNTIME_OBJECT_MISSING);
+       }
+
+       /*Check BATs alignment */
+       if (bpx->hseqbase != bpy->hseqbase || BATcount(bpx) != BATcount(bpy)) {
+               BBPunfix(bpx->batCacheid);
+               BBPunfix(bpy->batCacheid);
+               throw(MAL, "geom.point", "both point bats must have dense and 
aligned heads");
+       }
+
+       /*Create output BAT */
+       if ((bo = COLnew(bpx->hseqbase, TYPE_bit, BATcount(bpx), TRANSIENT)) == 
NULL) {
+               BBPunfix(bpx->batCacheid);
+               BBPunfix(bpy->batCacheid);
+               throw(MAL, "geom.point", MAL_MALLOC_FAIL);
+       }
+
+       /*Iterate over the Point BATs and determine if they are in Polygon 
represented by vertex BATs */
+       px = (dbl *) Tloc(bpx, 0);
+       py = (dbl *) Tloc(bpy, 0);
+       cnt = BATcount(bpx);
+       cs = (bit *) Tloc(bo, 0);
+#ifdef GEOMBULK_DEBUG
+    gettimeofday(&start, NULL);
+#endif
+
+       /*Call to the GPU function*/
+
+       /*
+        * Verify if GPU has enough memory to get all the data 
+        * otherwise do it in waves.
+        */
+
+       /*Lock until all the results are available*/
+
+#ifdef GEOMBULK_DEBUG
+    gettimeofday(&stop, NULL);
+    t = 1000 * (stop.tv_sec - start.tv_sec) + (stop.tv_usec - start.tv_usec) / 
1000;
+    fprintf(stdout, "pnpolyWithHoles %llu ms\n", t);
+#endif
+
+       bo->tsorted = bo->trevsorted = 0;
+       bo->tkey = 0;
+       BATrmprops(bo)
+       BATsetcount(bo, cnt);
+       BATsettrivprop(bo);
+       BBPunfix(bpx->batCacheid);
+       BBPunfix(bpy->batCacheid);
+       BBPkeepref(*out = bo->batCacheid);
+       return MAL_SUCCEED;
+}
+
+str
+wkbGContains_point_bat(bat *out, wkb **a, bat *point_x, bat *point_y, bat 
*point_z, int *srid)
+{
+    vertexWKB *verts = NULL;
+       wkb *geom = NULL;
+       str msg = NULL;
+       (void) point_z;
+
+       geom = (wkb *) *a;
+    if ((msg = getVerts(geom, &verts)) != MAL_SUCCEED) {
+        return msg;
+    }
+         
+       msg = GpnpolyWithHoles(out, (int) verts->nvert, verts->vert_x, 
verts->vert_y, verts->nholes, verts->holes_x, verts->holes_y, verts->holes_n, 
point_x, point_y);
+
+    if (verts)
+        freeVerts(verts);
+
+       return msg;
+}
diff --git a/geom/monetdb5/gpu.h b/geom/monetdb5/gpu.h
new file mode 100644
--- /dev/null
+++ b/geom/monetdb5/gpu.h
@@ -0,0 +1,27 @@
+/*
+ * 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 - 2016 MonetDB B.V.
+ */
+
+/*
+ * @a Romulo Goncalves
+ */
+
+#include <monetdb_config.h>
+#include "libgeom.h"
+#include "geom.h"
+
+#ifdef WIN32
+#ifndef LIBGEOM
+#define geom_export extern __declspec(dllimport)
+#else
+#define geom_export extern __declspec(dllexport)
+#endif
+#else
+#define geom_export extern
+#endif
+
+geom_export str wkbGContains_point_bat(int *res, wkb **geom, int *xBAT_id, int 
*yBAT_id, int *zBAT_id, int *srid);
diff --git a/geom/monetdb5/gpu.mal b/geom/monetdb5/gpu.mal
new file mode 100644
--- /dev/null
+++ b/geom/monetdb5/gpu.mal
@@ -0,0 +1,17 @@
+# 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 - 2016 MonetDB B.V.
+
+module geom;
+
+command GContains(a:wkb, x:dbl, y:dbl, z:dbl, srid:int) :bit
+address wkbContainsXYZ
+comment "Returns true if the Geometry a 'spatially contains' Geometry b";
+
+module batgeom;
+
+command GContains(a:wkb, px:bat[:dbl], py:bat[:dbl], pz:bat[:dbl], srid:int) 
:bat[:bit]
+address wkbGContains_point_bat
+comment "Returns true if the Geometry a 'spatially contains' Geometry b";
diff --git a/geom/sql/42_gpu.sql b/geom/sql/42_gpu.sql
new file mode 100644
--- /dev/null
+++ b/geom/sql/42_gpu.sql
@@ -0,0 +1,7 @@
+-- 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 - 2016 MonetDB B.V.
+
+CREATE FUNCTION G_Contains(a Geometry, x double, y double, z double, srid int) 
RETURNS BOOLEAN external name geom."GContains";
diff --git a/geom/sql/Makefile.ag b/geom/sql/Makefile.ag
--- a/geom/sql/Makefile.ag
+++ b/geom/sql/Makefile.ag
@@ -17,4 +17,11 @@ headers_sql_sfcgal = {
        SOURCES = 41_sfcgal.sql
 }
 
+headers_sql_gpu = {
+       #COND = HAVE_GPU
+       HEADERS = sql
+       DIR = libdir/monetdb5/createdb
+       SOURCES = 42_gpu.sql
+}
+
 EXTRA_DIST_DIR = Tests conformance functions pg_regression
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to