dmlc / dmlc/tl2cgen

treelite4j: Predictor constructor using`dlopen` not working as expected when model library path does not include a `/`

Open
#3 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
55
Forks
11
PR merge metrics
No merged PRs in 30d

Description

I'm trying to run a basic example with treelite4j, and I couldn't get the model to load as expected.
I was trying to use:

`Predictor treelitePredictor = new Predictor("myModel.so", treeliteThreads, true);`

but was getting the error:

```
Exception in thread "main" ml.dmlc.treelite4j.java.TreeliteError: [00:08:33] /local/home/thvasilo/repos/treelite/src/predictor/predictor.cc:175: Check failed: handle: Failed to load dynamic shared library `test00.so'
at ml.dmlc.treelite4j.java.TreeliteJNI.checkCall(TreeliteJNI.java:28)
at ml.dmlc.treelite4j.java.Predictor.initNativeLibrary(Predictor.java:94)
at ml.dmlc.treelite4j.java.Predictor.(Predictor.java:57)
at com.amazon.treelitetest.SimpleTreelitePrediction.main(SimpleTreelitePrediction.java:22)
```

Turns out that `dlopen` does not consider the input argument `const char* file` a path unless it contains a `/`, or not exactly at least:
From https://pubs.opengroup.org/onlinepubs/7908799/xsh/dlopen.html

>void *dlopen(const char *file, int mode); `file` is used to construct a pathname to the object file. **If `file` contains a slash character, the file argument is used as the pathname for the file. Otherwise, file is used in an implementation-dependent manner to yield a pathname.**

After I changed the call to:

`Predictor treelitePredictor = new Predictor("/path/to/myModel.so", treeliteThreads, true);` the model loaded fine.

So this is a bit of a sneaky bug that's possibly implementation/platform dependent. My env was Amazon Linux 2 on JDK 1.8.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.