parent
50f04dcae3
commit
ef257e6d96
@ -1,4 +1,3 @@
|
||||
if(WITH_GPU)
|
||||
nv_library(nccl_common SRCS nccl_gpu_common.cc DEPS device_context operator )
|
||||
nv_test(nccl_gpu_common_test SRCS nccl_gpu_common_test.cc DEPS nccl_common)
|
||||
endif()
|
||||
|
@ -1,33 +0,0 @@
|
||||
#include "paddle/operators/nccl/nccl_gpu_common.h"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
namespace paddle {
|
||||
namespace platform {
|
||||
|
||||
TEST(WaitGroup, wait) {
|
||||
WaitGroup wg;
|
||||
auto run_thread = [&wg](int idx) {
|
||||
wg.Add(1);
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
wg.Done();
|
||||
};
|
||||
|
||||
std::vector<std::thread> ths;
|
||||
constexpr const int TNUM = 5;
|
||||
for (int i = 0; i < TNUM; ++i) {
|
||||
ths.emplace_back(std::thread(run_thread, i));
|
||||
}
|
||||
wg.Wait();
|
||||
|
||||
for (int i = 0; i < TNUM; ++i) {
|
||||
ths[i].join();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace platform
|
||||
} // namespace paddle
|
@ -0,0 +1,71 @@
|
||||
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License. */
|
||||
#include "paddle/operators/nccl_op.h"
|
||||
|
||||
#include "glog/logging.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "paddle/platform/device_context.h"
|
||||
#include "paddle/platform/enforce.h"
|
||||
#include "paddle/platform/gpu_info.h"
|
||||
|
||||
#include <thrust/device_vector.h>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
static std::vector<int> gpu_list;
|
||||
|
||||
using f = paddle::framework;
|
||||
using ops = paddle::operators;
|
||||
|
||||
void AddOp(const std::string &type, const f::VariableNameMap &inputs,
|
||||
const f::VariableNameMap &outputs, f::AttributeMap attrs,
|
||||
paddle::framework::BlockDescBind *block) {
|
||||
for (auto kv : outputs) {
|
||||
for (auto v : kv.second) {
|
||||
auto var = block->Var(v);
|
||||
var->SetDataType(paddle::framework::DataType::FP32);
|
||||
}
|
||||
}
|
||||
|
||||
auto op = block->AppendOp();
|
||||
op->SetType(type);
|
||||
for (auto &kv : inputs) {
|
||||
op->SetInput(kv.first, kv.second);
|
||||
}
|
||||
for (auto &kv : outputs) {
|
||||
op->SetOutput(kv.first, kv.second);
|
||||
}
|
||||
op->SetAttrMap(attrs);
|
||||
}
|
||||
|
||||
TEST(NCCL, ncclInitOp) {
|
||||
f::ProgramDescBind program;
|
||||
f::BlockDescBind *block = program.Block(0);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
static constexpr int gpu_count = paddle::platform::GetCUDADeviceCount();
|
||||
for (int i = 0; i < gpu_count; ++i) {
|
||||
gpu_list.emplace_back(i);
|
||||
}
|
||||
if (dev_count <= 1) {
|
||||
LOG(WARNING)
|
||||
<< "Cannot test multi-gpu nccl, because the CUDA device count is "
|
||||
<< dev_count;
|
||||
return 0;
|
||||
}
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License. */
|
||||
#include "paddle/operators/nccl_op.h"
|
||||
|
||||
#include "glog/logging.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "paddle/platform/device_context.h"
|
||||
#include "paddle/platform/enforce.h"
|
||||
#include "paddle/platform/gpu_info.h"
|
||||
|
||||
#include <thrust/device_vector.h>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
static std::vector<int> gpu_list;
|
||||
|
||||
using f = paddle::framework;
|
||||
using ops = paddle::operators;
|
||||
|
||||
void AddOp(const std::string &type, const f::VariableNameMap &inputs,
|
||||
const f::VariableNameMap &outputs, f::AttributeMap attrs,
|
||||
paddle::framework::BlockDescBind *block) {
|
||||
for (auto kv : outputs) {
|
||||
for (auto v : kv.second) {
|
||||
auto var = block->Var(v);
|
||||
var->SetDataType(paddle::framework::DataType::FP32);
|
||||
}
|
||||
}
|
||||
|
||||
auto op = block->AppendOp();
|
||||
op->SetType(type);
|
||||
for (auto &kv : inputs) {
|
||||
op->SetInput(kv.first, kv.second);
|
||||
}
|
||||
for (auto &kv : outputs) {
|
||||
op->SetOutput(kv.first, kv.second);
|
||||
}
|
||||
op->SetAttrMap(attrs);
|
||||
}
|
||||
|
||||
TEST(NCCL, ncclInitOp) {
|
||||
f::ProgramDescBind program;
|
||||
f::BlockDescBind *block = program.Block(0);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
static constexpr int gpu_count = paddle::platform::GetCUDADeviceCount();
|
||||
for (int i = 0; i < gpu_count; ++i) {
|
||||
gpu_list.emplace_back(i);
|
||||
}
|
||||
if (dev_count <= 1) {
|
||||
LOG(WARNING)
|
||||
<< "Cannot test multi-gpu nccl, because the CUDA device count is "
|
||||
<< dev_count;
|
||||
return 0;
|
||||
}
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
import unittest, os
|
||||
import numpy as np
|
||||
import paddle.v2 as paddle
|
||||
from paddle.v2.framework.op import Operator
|
||||
import paddle.v2.framework.core as core
|
||||
from op_test import OpTest, create_op, set_input
|
||||
|
||||
gpu_list = "0,1,2,3"
|
@ -0,0 +1,36 @@
|
||||
import unittest, os
|
||||
import numpy as np
|
||||
import paddle.v2 as paddle
|
||||
from paddle.v2.framework.op import Operator
|
||||
import paddle.v2.framework.core as core
|
||||
from op_test import OpTest, create_op, set_input
|
||||
|
||||
gpu_list = "0,1,2,3"
|
||||
|
||||
if not core.is_compile_gpu() or not gpu_list:
|
||||
exit(0)
|
||||
|
||||
g_scope = core.Scope()
|
||||
g_ctx = core.DeviceContext.create(core.CPUPlace())
|
||||
|
||||
|
||||
class TestNCCLInit(unittest.TestCase):
|
||||
def test_init(self):
|
||||
self.op_type = "ncclInit"
|
||||
self.gpus = [int(g) for g in gpu_list.split(",")]
|
||||
|
||||
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()
|
Loading…
Reference in new issue