| 18 | } |
| 19 | |
| 20 | NCatboostCuda::TDocParallelDataSetsHolder NCatboostCuda::TDocParallelDataSetBuilder::BuildDataSet(const ui32 permutationCount, |
| 21 | NPar::ILocalExecutor* localExecutor) { |
| 22 | TDocParallelDataSetsHolder dataSetsHolder(DataProvider, |
| 23 | FeaturesManager, |
| 24 | LinkedTest); |
| 25 | |
| 26 | TSharedCompressedIndexBuilder<TDataSetLayout> compressedIndexBuilder(*dataSetsHolder.CompressedIndex, |
| 27 | localExecutor); |
| 28 | |
| 29 | dataSetsHolder.PermutationDataSets.resize(permutationCount); |
| 30 | |
| 31 | // |
| 32 | TDataPermutation learnLoadBalancingPermutation = dataSetsHolder.LearnDocPerDevicesSplit->Permutation; |
| 33 | |
| 34 | TCudaBuffer<float, NCudaLib::TStripeMapping> targets; |
| 35 | TCudaBuffer<float, NCudaLib::TStripeMapping> weights; |
| 36 | |
| 37 | const auto cpuTargets = *DataProvider.TargetData->GetTarget(); |
| 38 | const auto targetCount = cpuTargets.size(); |
| 39 | targets.Reset(dataSetsHolder.LearnDocPerDevicesSplit->Mapping, targetCount); |
| 40 | weights.Reset(dataSetsHolder.LearnDocPerDevicesSplit->Mapping); |
| 41 | |
| 42 | targets.Write(Flatten2D(learnLoadBalancingPermutation.Gather2D(*DataProvider.TargetData->GetTarget()))); |
| 43 | weights.Write(learnLoadBalancingPermutation.Gather(GetWeights(*DataProvider.TargetData))); |
| 44 | |
| 45 | for (ui32 permutationId = 0; permutationId < permutationCount; ++permutationId) { |
| 46 | dataSetsHolder.PermutationDataSets[permutationId] = THolder<TDocParallelDataSet>(new TDocParallelDataSet(DataProvider, |
| 47 | dataSetsHolder.CompressedIndex, |
| 48 | GetPermutation(DataProvider, permutationId), |
| 49 | learnLoadBalancingPermutation, |
| 50 | dataSetsHolder.LearnDocPerDevicesSplit->SamplesGrouping, |
| 51 | TTarget<NCudaLib::TStripeMapping>(targets.ConstCopyView(), |
| 52 | weights.ConstCopyView(), |
| 53 | /*isPairWeights*/ false))); |
| 54 | } |
| 55 | |
| 56 | if (LinkedTest != nullptr) { |
| 57 | TCudaBuffer<float, NCudaLib::TStripeMapping> testTargets; |
| 58 | TCudaBuffer<float, NCudaLib::TStripeMapping> testWeights; |
| 59 | |
| 60 | TDataPermutation testLoadBalancingPermutation = dataSetsHolder.TestDocPerDevicesSplit->Permutation; |
| 61 | |
| 62 | testTargets.Reset(dataSetsHolder.TestDocPerDevicesSplit->Mapping, targetCount); |
| 63 | testWeights.Reset(dataSetsHolder.TestDocPerDevicesSplit->Mapping); |
| 64 | |
| 65 | testTargets.Write(Flatten2D(testLoadBalancingPermutation.Gather2D(*LinkedTest->TargetData->GetTarget()))); |
| 66 | testWeights.Write(testLoadBalancingPermutation.Gather(GetWeights(*LinkedTest->TargetData))); |
| 67 | |
| 68 | dataSetsHolder.TestDataSet = THolder<TDocParallelDataSet>(new TDocParallelDataSet(*LinkedTest, |
| 69 | dataSetsHolder.CompressedIndex, |
| 70 | GetIdentityPermutation(*LinkedTest), |
| 71 | testLoadBalancingPermutation, |
| 72 | dataSetsHolder.TestDocPerDevicesSplit->SamplesGrouping, |
| 73 | TTarget<NCudaLib::TStripeMapping>(testTargets.ConstCopyView(), |
| 74 | testWeights.ConstCopyView(), |
| 75 | /*isPairWeights*/ false))); |
| 76 | } |
| 77 | |