Open archenroot opened 6 years ago
Welcome back :) It has a C API, that should be pretty easy to map. Give it a try with this new guide: https://github.com/bytedeco/javacpp/wiki/Mapping-Recipes
@saudet - ok, I prepared project skeleton with cppbuil.sh and created general infomapper class, now I strugle little bit, but I will come with real questions and possibly multiple :-)
@saudet - I kicked off the module creation at: https://github.com/archenroot/javacpp-presets
I will go trought the output, there is just something related to some JSON mapping comming from gunrock which generated some mess. When you have minute, could you quickly check whats wrong.
Additionally I don't much understand from documentation what the link property means. At some projects I look at it has value like "hdf5@1", wasn't able to find much explained about this.
Thx for kick me further to finish this piece of preset.
We should be mapping only the C/C++ API, not anything related to JSON. What do you mean?
The "link" value is just the name of the library, and if something is attached to the suffix, like the version, we put it after @
, that's all. I guess we should add that to the doc:
http://bytedeco.org/javacpp/apidocs/org/bytedeco/javacpp/annotation/Platform.html#link--
@saudet - link is clear.
Regarding json, I will paste here what has been produced by javacpp, just jump on cigarette...
@saudet - Ok, so I successfully generated the JNI wrapper, but its non-compilable:
gunrock.java:749: error: <identifier> expected
@Namespace("json_spirit") @MemberGetter public static native @Const @ByRef @Name("Value_impl<Config>::null") json_spirit::Value_impl<Config> Value_impl<Config>::null();
^
gunrock.java:749: error: ';' expected
@Namespace("json_spirit") @MemberGetter public static native @Const @ByRef @Name("Value_impl<Config>::null") json_spirit::Value_impl<Config> Value_impl<Config>::null();
^
gunrock.java:749: error: illegal start of type
@Namespace("json_spirit") @MemberGetter public static native @Const @ByRef @Name("Value_impl<Config>::null") json_spirit::Value_impl<Config> Value_impl<Config>::null();
^
gunrock.java:749: error: '(' expected
@Namespace("json_spirit") @MemberGetter public static native @Const @ByRef @Name("Value_impl<Config>::null") json_spirit::Value_impl<Config> Value_impl<Config>::null();
^
gunrock.java:749: error: illegal start of type
@Namespace("json_spirit") @MemberGetter public static native @Const @ByRef @Name("Value_impl<Config>::null") json_spirit::Value_impl<Config> Value_impl<Config>::null();
^
gunrock.java:749: error: <identifier> expected
@Namespace("json_spirit") @MemberGetter public static native @Const @ByRef @Name("Value_impl<Config>::null") json_spirit::Value_impl<Config> Value_impl<Config>::null();
^
6 errors
Current state is available here: https://github.com/archenroot/javacpp-presets
Any comments welcomed.
That doesn't look like the C API. Start with that, it'll be easier.
Anyway I will play with that a little first, this is also good studdy of javacpp after some time I used it last time...
No, like this: https://github.com/gunrock/gunrock/tree/master/shared_lib_tests Basically the "gunrock.h" include file only.
I see, thx. Will start with that.
Ok, mvn clean install success. I will add to the cppbuild.sh some condition to check if directory already exists, to prevent download and build, could be handy for debugging purposes.
Additionally it looks like I might not need any other header file then gunrock.h, but I am going to do some java test and maybe will provide some Info objects to remap some functions.
Again thanks for help buddy!
The cppbuild.sh builds in the presets already don't redownload or rebuild, please use the same pattern!
Yes, if the C API is enough for your needs, let's go with that at first. I'm sure it will be useful to others, or if not maybe they'll help out and enhance it. :)
I go with same pattern or at least try, I have now finished first translated program from C to Java like following (already committed progress - of course once all works I will squash commits into single one before merge request back to master javacpp-presets).
The code - is Javoized version of https://github.com/gunrock/gunrock/blob/master/shared_lib_tests/shared_lib_sssp.c: `public class Main {
public static void main(String[] args){
//gunrock gunrock = new gunrock();
gunrock.GRTypes grTypes = new gunrock.GRTypes();
grTypes.VTXID_TYPE(VTXID_INT);
grTypes.SIZET_TYPE(SIZET_INT);
grTypes.VALUE_TYPE(VALUE_INT);
int srcs[] = {0};
gunrock.GRSetup grSetup = InitSetup(1, srcs);
int num_nodes = 7; int num_edges = 15;
//int row_offsets[] = readFile("row.txt");
//int col_list[] = readFile("col.txt");
//int val_list = readFile("val.txt");
int row_offsets[] = {0, 3, 6, 9, 11, 14, 15, 15};
int col_indices[] = {1, 2, 3, 0, 2, 4, 3, 4, 5, 5, 6, 2, 5, 6, 6};
int edge_values[] = {39, 6, 41, 51, 63, 17, 10, 44, 41, 13, 58, 43, 50, 59, 35};
GRGraph grGraphO = new GRGraph();
GRGraph grGraphI = new GRGraph();
grGraphI.num_nodes(num_nodes);
grGraphI.num_edges(num_edges);
grGraphI.row_offsets(new Pointer().fill(row_offsets[0]));
grGraphI.col_indices(new Pointer().fill(col_indices[0]));
grGraphI.edge_values(new Pointer().fill(edge_values[0]));
gunrock_sssp(grGraphO, grGraphI, grSetup, grTypes);
Pointer labelsI = IntPointer.malloc(grGraphI.num_nodes());
ByteBuffer labelsO = grGraphO.node_value1().asByteBuffer();
byte[] arr = new byte[labelsO.remaining()];
for (int node = 0;node < grGraphI.num_nodes();++node){
System.out.format("Node_ID [%d] : Label [%d]\n", node, arr[node]);
}
}`
Line:
grGraphI.row_offsets(new Pointer().fill(row_offsets[0]));
Throws an exception(I am not sure about using fill() method... could be reason or bug in glibc?):
/usr/lib/jvm/oracle-jdk-bin-1.8/bin/java -javaagent:/opt/idea-ultimate-2018.2.4/lib/idea_rt.jar=45589:/opt/idea-ultimate-2018.2.4/bin -Dfile.encoding=UTF-8 -classpath /usr/lib/jvm/oracle-jdk-bin-1.8/jre/lib/charsets.jar:/usr/lib/jvm/oracle-jdk-bin-1.8/jre/lib/deploy.jar:/usr/lib/jvm/oracle-jdk-bin-1.8/jre/lib/ext/cldrdata.jar:/usr/lib/jvm/oracle-jdk-bin-1.8/jre/lib/ext/dnsns.jar:/usr/lib/jvm/oracle-jdk-bin-1.8/jre/lib/ext/jaccess.jar:/usr/lib/jvm/oracle-jdk-bin-1.8/jre/lib/ext/localedata.jar:/usr/lib/jvm/oracle-jdk-bin-1.8/jre/lib/ext/nashorn.jar:/usr/lib/jvm/oracle-jdk-bin-1.8/jre/lib/ext/sunec.jar:/usr/lib/jvm/oracle-jdk-bin-1.8/jre/lib/ext/sunjce_provider.jar:/usr/lib/jvm/oracle-jdk-bin-1.8/jre/lib/ext/sunpkcs11.jar:/usr/lib/jvm/oracle-jdk-bin-1.8/jre/lib/ext/zipfs.jar:/usr/lib/jvm/oracle-jdk-bin-1.8/jre/lib/javaws.jar:/usr/lib/jvm/oracle-jdk-bin-1.8/jre/lib/jce.jar:/usr/lib/jvm/oracle-jdk-bin-1.8/jre/lib/jsse.jar:/usr/lib/jvm/oracle-jdk-bin-1.8/jre/lib/management-agent.jar:/usr/lib/jvm/oracle-jdk-bin-1.8/jre/lib/plugin.jar:/usr/lib/jvm/oracle-jdk-bin-1.8/jre/lib/resources.jar:/usr/lib/jvm/oracle-jdk-bin-1.8/jre/lib/rt.jar:/home/zangetsu/proj/private/gpu/javacpp-presets_archenroot/gunrock/target/classes:/home/zangetsu/.m2/repository/org/bytedeco/javacpp/1.4.4-SNAPSHOT/javacpp-1.4.4-SNAPSHOT.jar:/home/zangetsu/proj/private/gpu/javacpp-presets_archenroot/gunrock/target/gunrock-linux-x86_64.jar:/home/zangetsu/proj/private/gpu/javacpp-presets_archenroot/gunrock/target/gunrock.jar Main
#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x00007f84fbaade75, pid=23945, tid=0x00007f84fc539700
#
# JRE version: Java(TM) SE Runtime Environment (8.0_192-b12) (build 1.8.0_192-b12)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.192-b12 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# C [libc.so.6+0x169e75] __memset_avx2_unaligned_erms+0xd5
#
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# /home/zangetsu/proj/private/gpu/javacpp-presets_archenroot/hs_err_pid23945.log
#
# If you would like to submit a bug report, please visit:
# http://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
Process finished with exit code 134 (interrupted by signal 6: SIGABRT)
error report file is here: https://paste.pound-python.org/show/wu09lb4sTfSUGzjZQieA/
Have you seen something like this on your journeys across C to Java world? I have Gentoo stable glibc:
Installed versions: 2.27-r6(2.2)^s(10:56:30 AM 10/29/2018)(multiarch multilib -audit -caps -compile-locales -doc -gd -hardened -headers-only -nscd -profile -selinux -suid -systemtap -vanilla)
Ok, my mistake, the problematic line should be:
grGraphI.row_offsets(new IntPointer(row_offsets[0]));
@saudet - the example is working fine - it executes on GPU without any error, but from C example:
gunrock_sssp(grapho, graphi, config, data_t);
////////////////////////////////////////////////////////////////////////////
int *labels = (int*)malloc(sizeof(int) * graphi->num_nodes);
labels = (int*)grapho->node_value1;
int node; for (node = 0; node < graphi->num_nodes; ++node)
printf("Node_ID [%d] : Label [%d]\n", node, labels[node]);
I don't know how to get the actual array. grapho.node_value1 is type of Pointer, how to obtain an array which it points to? This is last piece of sample code to print out distance. And I am there thanks to you.
Cast it by creating a new IntPointer.
I am playing around and being not able to find right way...
Case 1:
Pointer labels = IntPointer.malloc(grGraphI.num_nodes());
labels = grGraphO.node_value1();
IntPointer intl = new IntPointer(labels);
int nodes = row_offsets.length - 1;
for (int index =0;index < nodes;index++){
log("distance:" + intl.get(index));
}
produces:
input number of nodes:7
distance:0
[/home/zangetsu/proj/private/gpu/javacpp-presets/gunrock/cppbuild/linux-x86_64/gunrock/gunrock/util/array_utils.cuh, 209 @ gpu 0] keys cudaMalloc failed (CUDA error 2: out of memory)
distance:2147483647
distance:2147483647
[/home/zangetsu/proj/private/gpu/javacpp-presets/gunrock/cppbuild/linux-x86_64/gunrock/gunrock/app/sssp/sssp_app.cu, 200 @ gpu 0] SSSP Problem Enact Failed (CUDA error 2: out of memory)
distance:2147483647
distance:2147483647
distance:2147483647
distance:2147483647
Case 2:
IntPointer labels = (IntPointer) IntPointer.malloc(grGraphI.num_nodes());
produces:
[/home/zangetsu/proj/private/gpu/javacpp-presets/gunrock/cppbuild/linux-x86_64/gunrock/gunrock/app/enactor_loop.cuh, 781 @ gpu 0] FullQueue_Core failed. (CUDA error 77: an illegal memory access was encountered)
[/home/zangetsu/proj/private/gpu/javacpp-presets/gunrock/cppbuild/linux-x86_64/gunrock/gunrock/app/sssp/sssp_app.cu, 200 @ gpu 0] SSSP Problem Enact Failed (CUDA error 77: an illegal memory access was encountered)
[/home/zangetsu/proj/private/gpu/javacpp-presets/gunrock/cppbuild/linux-x86_64/gunrock/gunrock/util/array_utils.cuh, 550 @ gpu 0] distances cudaMemcpy D2H failed (CUDA error 77: an illegal memory access was encountered)
[/home/zangetsu/proj/private/gpu/javacpp-presets/gunrock/cppbuild/linux-x86_64/gunrock/gunrock/app/sssp/sssp_app.cu, 209 @ gpu 0] SSSP Problem Data Extraction Failed (CUDA error 77: an illegal memory access was encountered)
[/home/zangetsu/proj/private/gpu/javacpp-presets/gunrock/cppbuild/linux-x86_64/gunrock/gunrock/util/array_utils.cuh, 271 @ gpu 0] node_locks cudaFree failed (CUDA error 77: an illegal memory access was encountered)
[/home/zangetsu/proj/private/gpu/javacpp-presets/gunrock/cppbuild/linux-x86_64/gunrock/gunrock/util/array_utils.cuh, 271 @ gpu 0] node_locks cudaFree failed (CUDA error 77: an illegal memory access was encountered)
[/home/zangetsu/proj/private/gpu/javacpp-presets/gunrock/cppbuild/linux-x86_64/gunrock/gunrock/app/problem_base.cuh, 672 @ gpu 0] cudaEventDestroy failed (CUDA error 77: an illegal memory access was encountered)
[/home/zangetsu/proj/private/gpu/javacpp-presets/gunrock/cppbuild/linux-x86_64/gunrock/gunrock/app/problem_base.cuh, 672 @ gpu 0] cudaEventDestroy failed (CUDA error 77: an illegal memory access was encountered)
[/home/zangetsu/proj/private/gpu/javacpp-presets/gunrock/cppbuild/linux-x86_64/gunrock/gunrock/util/array_utils.cuh, 271 @ gpu 0] data_slices[] cudaFree failed (CUDA error 77: an illegal memory access was encountered)
[/home/zangetsu/proj/private/gpu/javacpp-presets/gunrock/cppbuild/linux-x86_64/gunrock/gunrock/util/array_utils.cuh, 271 @ gpu 0] row_offsets cudaFree failed (CUDA error 77: an illegal memory access was encountered)
Exception in thread "main" java.lang.ClassCastException: org.bytedeco.javacpp.Pointer cannot be cast to org.bytedeco.javacpp.IntPointer
Case 3;
IntPointer intl = new IntPointer(grGraphO.node_value1());
produces:
[/home/zangetsu/proj/private/gpu/javacpp-presets/gunrock/cppbuild/linux-x86_64/gunrock/gunrock/app/enactor_loop.cuh, 781 @ gpu 0] FullQueue_Core failed. (CUDA error 77: an illegal memory access was encountered)
distance:1284984256
distance:32736
[/home/zangetsu/proj/private/gpu/javacpp-presets/gunrock/cppbuild/linux-x86_64/gunrock/gunrock/app/sssp/sssp_app.cu, 200 @ gpu 0] SSSP Problem Enact Failed (CUDA error 77: an illegal memory access was encountered)
distance:0
distance:0
[/home/zangetsu/proj/private/gpu/javacpp-presets/gunrock/cppbuild/linux-x86_64/gunrock/gunrock/util/array_utils.cuh, 550 @ gpu 0] distances cudaMemcpy D2H failed (CUDA error 77: an illegal memory access was encountered)
distance:0
distance:0
[/home/zangetsu/proj/private/gpu/javacpp-presets/gunrock/cppbuild/linux-x86_64/gunrock/gunrock/app/sssp/sssp_app.cu, 209 @ gpu 0] SSSP Problem Data Extraction Failed (CUDA error 77: an illegal memory access was encountered)
distance:0
[/home/zangetsu/proj/private/gpu/javacpp-presets/gunrock/cppbuild/linux-x86_64/gunrock/gunrock/util/array_utils.cuh, 271 @ gpu 0] node_locks cudaFree failed (CUDA error 77: an illegal memory access was encountered)
[/home/zangetsu/proj/private/gpu/javacpp-presets/gunrock/cppbuild/linux-x86_64/gunrock/gunrock/util/array_utils.cuh, 271 @ gpu 0] node_locks cudaFree failed (CUDA error 77: an illegal memory access was encountered)
[/home/zangetsu/proj/private/gpu/javacpp-presets/gunrock/cppbuild/linux-x86_64/gunrock/gunrock/app/problem_base.cuh, 672 @ gpu 0] cudaEventDestroy failed (CUDA error 77: an illegal memory access was encountered)
[/home/zangetsu/proj/private/gpu/javacpp-presets/gunrock/cppbuild/linux-x86_64/gunrock/gunrock/app/problem_base.cuh, 672 @ gpu 0] cudaEventDestroy failed (CUDA error 77: an illegal memory access was encountered)
[/home/zangetsu/proj/private/gpu/javacpp-presets/gunrock/cppbuild/linux-x86_64/gunrock/gunrock/util/array_utils.cuh, 271 @ gpu 0] data_slices[] cudaFree failed (CUDA error 77: an illegal memory access was encountered)
[/home/zangetsu/proj/private/gpu/javacpp-presets/gunrock/cppbuild/linux-x86_64/gunrock/gunrock/util/array_utils.cuh, 271 @ gpu 0] row_offsets cudaFree failed (CUDA error 77: an illegal memory access was encountered)
Round 1 of sssp.
I am tired, its 5:20 am here :-), but thx for help my navigation... I mean I will continue on saturday.
I'm not sure why they allocate memory, assign it to labels
, but then assign another pointer right away to labels
. There's probably something wrong with that code...
There is actually the python counter example I found which imports ctype lib:
gunrock.sssp(labels, preds, nodes, edges, row, col, val, 1, sources, 0)
### sample results
print ' sssp labels (distance):',
for idx in range(nodes): print labels[0][idx],
labels is out parameter type of Pointer javacpp in my case at moment. Maybe I might enforce it in the parser directly to IntPointer?
There are 2 versions of sssp, one returns drGraph(C sample) and one int pointer(python sample with ctype lib), the header file define methods like:
/**
* @brief Single-source shortest path public interface.
*
* @param[out] grapho Output data structure contains results.
* @param[in] graphi Input data structure contains graph.
* @param[in] config Primitive-specific configurations.
* @param[in] data_t Primitive-specific data type setting.
*
* \return Elapsed run time in milliseconds
*/
float gunrock_sssp(
struct GRGraph* grapho, // Output graph / results
const struct GRGraph* graphi, // Input graph structure
const struct GRSetup* config, // Flag configurations
const struct GRTypes data_t); // Data type Configurations
/**
* @brief Single-source shortest path simple public interface.
*
* @param[out] distances Return shortest distances.
* @param[out] preds Return predecessor of each node
* @param[in] num_nodes Input graph number of nodes.
* @param[in] num_edges Input graph number of edges.
* @param[in] row_offsets Input graph row_offsets.
* @param[in] col_indices Input graph col_indices.
* @param[in] edge_values Input graph edge weight.
* @param[in] num_iters How many rounds of SSSP do we want to run.
* @param[in] source Source node to start.
* @param[in] mark_preds Whether to mark the predecessors.
*
* \return Elapsed run time in milliseconds
*/
float sssp(
unsigned int* distances, // Return shortest distances
int* preds,
const int num_nodes, // Input graph number of nodes
const int num_edges, // Input graph number of edges
const int* row_offsets, // Input graph row_offsets
const int* col_indices, // Input graph col_indices
const unsigned int* edge_values, // Input graph edge weight
const int num_iters,
int* source,
const bool mark_preds);
I tried to rewrite now python example with sssp method:
public static void main(String[] args){
//gunrock gunrock = new gunrock();
gunrock.GRTypes grTypes = new gunrock.GRTypes();
grTypes.VTXID_TYPE(VTXID_INT);
grTypes.SIZET_TYPE(SIZET_INT);
grTypes.VALUE_TYPE(VALUE_INT);
int srcs[] = {0};
gunrock.GRSetup grSetup = InitSetup(1, srcs);
int num_nodes = 7; int num_edges = 15;
//int row_offsets[] = readFile("row.txt");
//int col_list[] = readFile("col.txt");
//int val_list = readFile("val.txt");
int row_offsets[] = {0, 3, 6, 9, 11, 14, 15, 15};
int col_indices[] = {1, 2, 3, 0, 2, 4, 3, 4, 5, 5, 6, 2, 5, 6, 6};
int edge_values[] = {39, 6, 41, 51, 63, 17, 10, 44, 41, 13, 58, 43, 50, 59, 35};
//Python sample based
IntPointer row = new IntPointer(row_offsets.length);
IntPointer col = new IntPointer(col_indices.length);
IntPointer edg = new IntPointer(edge_values.length);
int nodes = row_offsets.length -1;
int edges = col_indices.length;
IntPointer labels = new IntPointer(nodes);
IntPointer preds = new IntPointer(nodes);
IntPointer sources = new IntPointer(1);
sssp(labels, preds, nodes, edges, row, col, edg, 1, sources, true);
for (int index =0;index < nodes;index++){
log("distance:" + labels.get(index));
}
Its also throwing some errors:
distance:2147483647
distance:2147483647
[/home/zangetsu/proj/private/gpu/javacpp-presets/gunrock/cppbuild/linux-x86_64/gunrock/gunrock/app/sssp/sssp_problem.cuh, 594 @ gpu 0] SSSPProblem cudaMemcpy frontier_queues failed (CUDA error 11: invalid argument)
distance:2147483647
distance:2147483647
distance:2147483647
distance:2147483647
[/home/zangetsu/proj/private/gpu/javacpp-presets/gunrock/cppbuild/linux-x86_64/gunrock/gunrock/app/sssp/sssp_app.cu, 193 @ gpu 0] SSSP Problem Data Reset Failed (CUDA error 11: invalid argument)
distance:2147483647
Round 1 of sssp.
Allocating arrays with lengths row_offsets.length
, etc won't initialize them with any values...
The same with the other example, those there should be something like:
grGraphI.row_offsets(new IntPointer(row_offsets));
...
Yeah I got it, hm, actually I do now python vs c code result merging as they differ on same set, could be some graph algo customization sssp vs gunrock_sssp, but that is off topic here as relates to gunrock internals.
The important thing is:
Current dir: /home/zangetsu/proj/private/gpu/javacpp-presets_archenroot
Current dir: /home/zangetsu/proj/private/gpu/javacpp-presets_archenroot
Current dir: /home/zangetsu/proj/private/gpu/javacpp-presets_archenroot
input number of nodes:7
distance:0
distance:3
distance:4
distance:5
distance:10
distance:13
distance:16
Round 1 of sssp.
0 1 0 queue3 oversize : 10 -> 14
JavaCPP rocks :1st_place_medal:
just for additional info what I observe when running on same data the PYTHON sample which uses sssp method: sssp labels (distance):
3
0
5
8
7
14
19
I will probably look into the other header files but only after some analysis. Anyway I will clean up the project, squash commits and create merge request. But it will require few days, I will also consider remapping C methods to some Java looking methods, etc. (cosmetics).
Not sure which of other header files will be useful, and or handy to cover as well, but will ask at gunrock itself first. They were thinking long time ago about having jgunrock, but due to resources (and not being probably aware of javacpp) it remained unfinished (never started), so they are also happy to have this.
Thx a lot for asistence with this. I will leave this open for any kind of discussion until we merge this into presets main branch...
@saudet - just small update. I will commit as soon as possible the Gunrock. I now work on integrate Gunrock Java API into Neo4j as custom algorithm, additionally I look at compression sparse column for graph data in binary format, etc...
@saudet - Could you review: https://github.com/archenroot/javacpp-presets?organization=archenroot&organization=archenroot
Or should I do merge requests, etc. The library requires CUDA and Boost 1.58-1.6* installed. Is there any way for such kind of dependencies to enforce by JavaCPP (it might be hard as per distro package manager...)
We can install Boost in the cppbuild.sh file as with Caffe, and for CUDA just make sure install-travis.sh downloads and installs it.
@saudet - will check and update it.
Some time passed I got back to JavaCPP :-)
In my current scope there is now: https://gunrock.github.io/docs/
Is it somethink you might be interested at Skymind projects with deeplearning4j as well, in such case maybe you could help me with preset generation :-)
Let me know and all the best.
NOTE: Guys were discussing to bind it to fasade like Apache TinkerPop back in time... https://github.com/gunrock/gunrock/issues/111 but is related to my current research focus to show what we can do on single Nvidia DGX-2 beast as Gunrock supports OpenMP, maybe in future they will support MPI to distribute accross gpu cluster..., but lets start small better now.
Ladislav