dmlc / dmlc/tl2cgen

Thread safe issue when multiple threads using the same .so file

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

Description

I am currently using C API for .so xgboost model loading and multiple thread will use the same model for prediction, I would like to know if the prediction be thread safe for prediction? In the real run, the first prediction will be extremely time consuming but subsequent prediction will decrease dramatically.

Here is the code:
`
TL2cgenPredictorHandle pred;
auto ret = TL2cgenPredictorLoad(new_model_path.c_str(),
/*num_worker_thread=*/1,
&pred);
std::vector> futures;
Common::ThreadPool pool(21); // Assuming ThreadPool is implemented and takes the number of threads as a parameter
for (size_t i = 0; i < ticker_universe.size(); ++i) {
auto future = pool.enqueue(&ticker_universe,&pred, i]() {
calculate(ticker_universe[i], pred);
});
futures.push_back(std::move(future));
}
for (auto &future : futures) {
future.get();
}
`
And the calculate(ticker_universe[i], pred) function will create the dmat and use the same pred to calculate, will this be thread safe?

Contributor guide

No contributing guide indexed for this repository

Research direction

The reported entry points are TL2cgenPredictorLoad, the shared pred handle, calculate(...), and the 21-worker ThreadPool example; start by tracing how prediction and DMatrix creation use that handle. Reproduce the concurrent call pattern and check existing API documentation or tests for thread-safety and first-call timing; done means the supported usage and observed behavior are documented or covered by a focused test.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
machine-learning
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.