- udf_sos_cpp_init.py: creates the schema, input & output tables, and loads test data
- udf_sos_cpp_proc.cu: implements the UDF itself
- makefile: compiles the UDF
- udf_sos_cpp_exec.py: creates & executes the UDF
All commands should be run as the
gpudb user.gpudb-accessible directory on the
Kinetica head node, the example can be run as follows, optionally
specifying the database host and a username & password to the Python scripts:
udf_example_cpp schema,
udf_sos_in_table & udf_sos_out_table, each holding 10,000 records; the
former containing pairs of numbers and the latter containing the sums of squares
of those numbers. Each table will carry an id, which can be used to
associate input values to output sums.
To verify the existence of the tables, in GAdmin, click Data >
Tables. Both tables should appear in the udf_example_cpp
schema, each with 10,000 records.
To verify the calculations, click Query > KiSQL. Enter
the following query into the SQL Statement box:
Execution Detail
While the example UDF itself can run against multiple tables, the example run will use a single schema-qualified table,udf_example_cpp.udf_sos_in_table,
as input and a matching schema-qualified table,
udf_example_cpp.udf_sos_out_table, for output.
The input table will contain two float columns and be populated with 10,000
pairs of randomly-generated numbers. The output table will contain one float
column that will hold the sums calculated by the UDF. Both tables will also
contain an int column that is the calculation identifier, allowing the input
data to be matched up with the output data after the UDF has run.
The UDF will assume the first column of the input table, as defined
in the original table creation process, is the identifier field. All
of the remaining columns after the first will be used in the
sum-of-squares calculation.
udf_sos_cpp_init.py
This initialization script creates the schema, input & output tables, and populates the input data using the standard Kinetica Python API, all outside of the UDF execution framework. Several aspects of the initialization process are noteworthy:- The external database connection, indicative of the use of the standard Kinetica Python API—the UDF will not have this, as it runs within the database:
- Schema, input, and output table creation:
udf_sos_cpp_proc.cu
This is the UDF itself. It uses the Kinetica C++ UDF API to compute the sums of squares of input table columns and output those sums to an output table. It runs within the UDF execution framework, and as such, is not called directly—instead, it is registered and launched by udf_sos_cpp_exec.py. Noteworthy in the UDF are the following:- The initial call to
ProcData()to access the database:
- The size of the output table must be specified before writing to it:
- The final call to
complete()to mark the process as finished and ready for clean-up:
makefile
This standard makefile is used to compile the C++ UDF source before registering the UDF with udf_sos_cpp_exec.py. Noteworthy in the makefile are the following:- The assumption of the C++ UDF library installed at the default location of a typical Kinetica deployment, and the location of a local CUDA install:
- The inclusion of Proc.cpp & Proc.hpp as the only UDF-centric compilation dependence: