File: allreduce_base_test.cc

package info (click to toggle)
rabit 0.0~git20200628.74bf00a-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 720 kB
  • sloc: cpp: 5,015; ansic: 710; python: 360; makefile: 306; sh: 136
file content (66 lines) | stat: -rw-r--r-- 1,976 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#define RABIT_CXXTESTDEFS_H
#include <gtest/gtest.h>

#include <string>
#include <iostream>
#include "../../src/allreduce_base.h"

TEST(allreduce_base, init_task)
{
  rabit::engine::AllreduceBase base;

  std::string rabit_task_id = "rabit_task_id=1";
  char cmd[rabit_task_id.size()+1];
  std::copy(rabit_task_id.begin(), rabit_task_id.end(), cmd);
  cmd[rabit_task_id.size()] = '\0';

  char* argv[] = {cmd};
  base.Init(1, argv);
  EXPECT_EQ(base.task_id, "1");
}

TEST(allreduce_base, init_with_cache_on)
{
  rabit::engine::AllreduceBase base;

  std::string rabit_task_id = "rabit_task_id=1";
  char cmd[rabit_task_id.size()+1];
  std::copy(rabit_task_id.begin(), rabit_task_id.end(), cmd);
  cmd[rabit_task_id.size()] = '\0';

  std::string rabit_bootstrap_cache = "rabit_bootstrap_cache=1";
  char cmd2[rabit_bootstrap_cache.size()+1];
  std::copy(rabit_bootstrap_cache.begin(), rabit_bootstrap_cache.end(), cmd2);
  cmd2[rabit_bootstrap_cache.size()] = '\0';

  std::string rabit_debug = "rabit_debug=1";
  char cmd3[rabit_debug.size()+1];
  std::copy(rabit_debug.begin(), rabit_debug.end(), cmd3);
  cmd3[rabit_debug.size()] = '\0';

  char* argv[] = {cmd, cmd2, cmd3};
  base.Init(3, argv);
  EXPECT_EQ(base.task_id, "1");
  EXPECT_EQ(base.rabit_bootstrap_cache, 1);
  EXPECT_EQ(base.rabit_debug, 1);
}

TEST(allreduce_base, init_with_ring_reduce)
{
  rabit::engine::AllreduceBase base;

  std::string rabit_task_id = "rabit_task_id=1";
  char cmd[rabit_task_id.size()+1];
  std::copy(rabit_task_id.begin(), rabit_task_id.end(), cmd);
  cmd[rabit_task_id.size()] = '\0';

  std::string rabit_reduce_ring_mincount = "rabit_reduce_ring_mincount=1";
  char cmd2[rabit_reduce_ring_mincount.size()+1];
  std::copy(rabit_reduce_ring_mincount.begin(), rabit_reduce_ring_mincount.end(), cmd2);
  cmd2[rabit_reduce_ring_mincount.size()] = '\0';

  char* argv[] = {cmd, cmd2};
  base.Init(2, argv);
  EXPECT_EQ(base.task_id, "1");
  EXPECT_EQ(base.reduce_ring_mincount, 1);
}