test_nccl_init_op.py 985 字节
Newer Older
D
Dong Zhihong 已提交
1 2 3
import unittest, os
import numpy as np
import paddle.v2 as paddle
Q
Qiao Longfei 已提交
4 5
from paddle.v2.fluid.op import Operator
import paddle.v2.fluid.core as core
D
Dong Zhihong 已提交
6 7
from op_test import OpTest, create_op, set_input

D
Dong Zhihong 已提交
8
if not core.is_compile_gpu():
D
Dong Zhihong 已提交
9 10
    exit(0)

D
Dong Zhihong 已提交
11
gpu_count = core.get_cuda_device_count()
D
dong zhihong 已提交
12 13

if gpu_count <= 1:
D
dong zhihong 已提交
14
    exit(0)
D
dong zhihong 已提交
15

D
Dong Zhihong 已提交
16 17 18 19 20 21 22
g_scope = core.Scope()
g_ctx = core.DeviceContext.create(core.CPUPlace())


class TestNCCLInit(unittest.TestCase):
    def test_init(self):
        self.op_type = "ncclInit"
D
Dong Zhihong 已提交
23
        self.gpus = range(gpu_count)
D
Dong Zhihong 已提交
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39

        self.inputs = {}
        self.attrs = {"gpus": self.gpus}
        g_scope.var("Communicator").get_communicator()
        self.outputs = {"Communicator": g_scope.find_var("Communicator")}
        nccl_init = create_op(
            g_scope,
            op_type=self.op_type,
            inputs=self.inputs,
            outputs=self.outputs,
            attrs=self.attrs)
        nccl_init.run(g_scope, g_ctx)


if __name__ == "__main__":
    unittest.main()