MCPcopy Create free account
hub / github.com/catboost/catboost / TestReduce

Function TestReduce

catboost/cuda/cuda_lib/ut/test_reduce.cpp:51–113  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

49 }
50
51 void TestReduce(const size_t partSize = 64 * 64,
52 const size_t partCountBase = 2000,
53 bool performanceOnly = false,
54 bool compress = false,
55 bool reduceSingle = false) {
56 TRandom rand(0);
57 SetDefaultProfileMode(EProfileMode::ImplicitLabelSync);
58 auto& profiler = GetProfiler();
59
60 TVector<float> dataCpu;
61 TVector<float> reducedDataCpu;
62 for (ui32 i = 0; i < dataCpu.size(); ++i) {
63 dataCpu[i] = (float)rand.NextUniform();
64 }
65
66 for (int tr = 0; tr < tries; ++tr) {
67 const size_t randPart = 1 + partCountBase * 0.05;
68 const size_t partCount = partCountBase + (tr == 0 ? randPart : rand.NextUniformL() % randPart);
69
70 auto beforeReduceMapping = TStripeMapping::RepeatOnAllDevices(partCount, partSize);
71 // auto singleMapping = TDeviceMapping<MT_SINGLE>::Create(0, partCount * partSize * TCudaManager::GetDeviceCount());
72
73 auto afterReduceMapping = TStripeMapping::SplitBetweenDevices(partCount, partSize);
74 if (reduceSingle) {
75 TMappingBuilder<TStripeMapping> builder;
76 builder.SetSizeAt(0, partCount);
77 afterReduceMapping = builder.Build(partSize);
78 }
79
80 auto data = TStripeBuffer<float>::Create(beforeReduceMapping);
81
82 dataCpu.resize(beforeReduceMapping.MemorySize());
83 reducedDataCpu.clear();
84 reducedDataCpu.resize(partCount * partSize);
85
86 if (!performanceOnly) {
87 for (ui32 i = 0; i < dataCpu.size(); ++i) {
88 dataCpu[i] = (float)rand.NextUniform();
89 reducedDataCpu[i % reducedDataCpu.size()] += dataCpu[i];
90 }
91 data.Write(dataCpu);
92 }
93
94 TReducer<decltype(data)> reducer;
95 {
96 TString label = compress ? "ReduceCompressed" : "Reduce";
97 if (reduceSingle) {
98 label += " (to single)";
99 }
100 auto guard = profiler.Profile(label);
101 reducer(data, afterReduceMapping, compress);
102 }
103
104 if (!performanceOnly) {
105 TVector<float> reducedGpu;
106 data.Read(reducedGpu);
107
108 for (ui32 i = 0; i < reducedDataCpu.size(); ++i) {

Callers 1

Y_UNIT_TESTFunction · 0.70

Calls 12

SetDefaultProfileModeFunction · 0.85
NextUniformMethod · 0.80
NextUniformLMethod · 0.80
MemorySizeMethod · 0.80
CreateFunction · 0.50
sizeMethod · 0.45
BuildMethod · 0.45
resizeMethod · 0.45
clearMethod · 0.45
WriteMethod · 0.45
ProfileMethod · 0.45
ReadMethod · 0.45

Tested by

no test coverage detected