Open stonebrakert6 opened 1 year ago
LGBM_BoosterPredictForMatSingleRowFastInit()-> Booster::SetSingleRowPredictor
I think the second example can indeed race but I'm not sure how the first one does currently race before #6024 because there's a unique lock here: https://github.com/microsoft/LightGBM/blob/0f7983b6c3443154441cecaa342462d4567760b7/src/c_api.cpp#L377
Description
When
Predictor::Predictor
is invoked for a shared Booster between multiple threads, it causes data races for shared data in Boosting object(GBDT
)Here is an API i.e LGBM_BoosterPredictForMatSingleRowFastInit() which if called from 2 separate threads concurrently using the same booster would cause data race(see the fully reproducible code below)
LGBM_BoosterPredictForMatSingleRowFastInit()-> Booster::SetSingleRowPredictor -> SingleRowPredictor::SingleRowPredictor() ->Predictor::Predictor() -> GBDT::InitPredict()
which writes concurrently i.e data race to variables(atleast)
num_iteration_for_pred_
andstart_iteration_for_pred_
of Boosting object(concretelyGBDT
)src/boosting/gbdt.h:422
Here is another/alternate API i.e LGBM_BoosterPredictForMat() which when invoked concurrently for the same Booster, would cause data race
LGBM_BoosterPredictForMat() -> Booster::Predict() -> Booster::CreatePredictor() -> Predictor::Predictor()
See Issue 6024 comments here and here
6024
Below is the code which when ran with Thread Sanitizer should reproduce/prove the race I am trying to share a
BoosterHandle
between multiple threads only for inference/prediction. I intend to use the APILGBM_BoosterPredictForMatSingleRowFast
and hence need to useLGBM_BoosterPredictForMatSingleRowFastInit
to create/initialize aFastConfigHandle
.Reproducible example
Environment info
LightGBM version or commit hash:
git log --oneline
8ed371ce (HEAD -> master, origin/master, origin/HEAD) set explicit number of threads in every OpenMP
parallel
region (#6135)Command(s) you used to install LightGBM
Additional Comments