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

Function TestSampleMeanDistributed

tests/cpp/common/test_stats.cc:150–174  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

148}
149
150void TestSampleMeanDistributed(Context const* ctx) {
151 std::size_t m{32}, n{16};
152 auto device = ctx->Device();
153 std::int32_t n_workers =
154 device.IsCPU() ? std::min(4u, std::thread::hardware_concurrency()) : curt::AllVisibleGPUs();
155 collective::TestDistributedGlobal(n_workers, [m, n, device, n_workers] {
156 auto rank = collective::GetRank();
157 Context ctx = device.IsCUDA() ? MakeCUDACtx(DistGpuIdx()) : Context{};
158 collective::GetWorkerLocalThreads(collective::GetWorldSize(), &ctx);
159 linalg::Matrix<float> data({m, n}, ctx.Device());
160 auto h_data = data.HostView();
161 for (std::size_t i = 0; i < m; ++i) {
162 for (std::size_t j = 0; j < n; ++j) {
163 h_data(i, j) = i + (m * rank) + j;
164 }
165 }
166 linalg::Vector<float> mean;
167 SampleMean(&ctx, false, data, &mean);
168 ASSERT_EQ(mean.Size(), n);
169 double total = n_workers * m;
170 for (std::size_t i = 0; i < n; ++i) {
171 ASSERT_EQ(mean(i), (i + total - 1.0 + i) * total / 2.0 / total);
172 }
173 });
174}
175
176void TestWeightedSampleMean(Context const* ctx) {
177 std::size_t m{32}, n{16};

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
SampleMeanFunction · 0.50
DeviceMethod · 0.45
IsCPUMethod · 0.45
IsCUDAMethod · 0.45
HostViewMethod · 0.45

Tested by

no test coverage detected