Skip to content

treelite4j: Predictor constructor usingdlopen not working as expected when model library path does not include a / #3

@thvasilo

Description

@thvasilo

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.<init>(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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions