MCPcopy Create free account
hub / github.com/dmlc/xgboost / TestWeightedSampleMeanDistributed

Function TestWeightedSampleMeanDistributed

tests/cpp/common/test_stats.cc:203–229  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

201}
202
203void TestWeightedSampleMeanDistributed(Context const* ctx) {
204 std::size_t m{32}, n{16};
205 auto device = ctx->Device();
206 std::int32_t n_workers =
207 device.IsCPU() ? std::min(4u, std::thread::hardware_concurrency()) : curt::AllVisibleGPUs();
208
209 collective::TestDistributedGlobal(n_workers, [m, n, device, n_workers] {
210 auto rank = collective::GetRank();
211 Context ctx = device.IsCUDA() ? MakeCUDACtx(DistGpuIdx()) : Context{};
212 collective::GetWorkerLocalThreads(collective::GetWorldSize(), &ctx);
213 linalg::Matrix<float> data({m, n}, ctx.Device());
214 auto h_data = data.HostView();
215 for (std::size_t i = 0; i < m; ++i) {
216 for (std::size_t j = 0; j < n; ++j) {
217 h_data(i, j) = i + (m * rank) + j;
218 }
219 }
220 HostDeviceVector<float> w{m, 1.0f, ctx.Device()};
221 linalg::Vector<float> mean;
222 WeightedSampleMean(&ctx, false, data, w, &mean);
223 ASSERT_EQ(mean.Size(), n);
224 double total = n_workers * m;
225 for (std::size_t i = 0; i < n; ++i) {
226 ASSERT_EQ(mean(i), (i + total - 1.0 + i) * total / 2.0 / total);
227 }
228 });
229}
230} // namespace
231
232TEST(Stats, SampleMean) {

Callers 1

TESTFunction · 0.85

Calls 13

AllVisibleGPUsFunction · 0.85
TestDistributedGlobalFunction · 0.85
GetRankFunction · 0.85
MakeCUDACtxFunction · 0.85
DistGpuIdxFunction · 0.85
GetWorkerLocalThreadsFunction · 0.85
GetWorldSizeFunction · 0.85
WeightedSampleMeanFunction · 0.50
DeviceMethod · 0.45
IsCPUMethod · 0.45
IsCUDAMethod · 0.45
HostViewMethod · 0.45

Tested by

no test coverage detected