!4170 dlopen cpu mpi adapter
Merge pull request !4170 from kisnwang/disable-host-mpipull/4170/MERGE
commit
234a3fd431
@ -0,0 +1,61 @@
|
||||
/**
|
||||
* Copyright 2020 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* 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 "runtime/device/cpu/mpi/mpi_export.h"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "runtime/device/cpu/mpi/mpi_adapter.h"
|
||||
|
||||
int GetMPIRankId() {
|
||||
auto inst = mindspore::device::cpu::MPIAdapter::Instance();
|
||||
if (inst == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
return inst->GetRankId();
|
||||
}
|
||||
|
||||
int GetMPIRankSize() {
|
||||
auto inst = mindspore::device::cpu::MPIAdapter::Instance();
|
||||
if (inst == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
return inst->GetRankSize();
|
||||
}
|
||||
|
||||
bool MPIReduceScatter(const float *input, float *output, const std::vector<int> &ranks_group, size_t data_num,
|
||||
const std::string &op_type) {
|
||||
auto inst = mindspore::device::cpu::MPIAdapter::Instance();
|
||||
if (inst == nullptr) {
|
||||
return false;
|
||||
}
|
||||
return inst->ReduceScatter(input, output, ranks_group, data_num, op_type);
|
||||
}
|
||||
|
||||
bool MPIReduceScatterOverwriteInput(float *input, const std::vector<int> &ranks_group, size_t in_data_num,
|
||||
size_t output_size, const std::string &op_type, float *output) {
|
||||
auto inst = mindspore::device::cpu::MPIAdapter::Instance();
|
||||
if (inst == nullptr) {
|
||||
return false;
|
||||
}
|
||||
return inst->ReduceScatterOverwriteInput(input, ranks_group, in_data_num, output_size, op_type, output);
|
||||
}
|
||||
|
||||
bool MPIAllGather(const float *input, float *output, const std::vector<int> &ranks_group, size_t data_num) {
|
||||
auto inst = mindspore::device::cpu::MPIAdapter::Instance();
|
||||
if (inst == nullptr) {
|
||||
return false;
|
||||
}
|
||||
return inst->AllGather(input, output, ranks_group, data_num);
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
/**
|
||||
* Copyright 2020 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef MINDSPORE_CCSRC_RUNTIME_DEVICE_CPU_MPI_MPI_EXPORT_H_
|
||||
#define MINDSPORE_CCSRC_RUNTIME_DEVICE_CPU_MPI_MPI_EXPORT_H_
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#ifndef FUNC_EXPORT
|
||||
#define FUNC_EXPORT __attribute__((visibility("default")))
|
||||
#endif
|
||||
|
||||
extern "C" FUNC_EXPORT FUNC_EXPORT int GetMPIRankId();
|
||||
extern "C" FUNC_EXPORT FUNC_EXPORT int GetMPIRankSize();
|
||||
extern "C" FUNC_EXPORT bool MPIReduceScatter(const float *input, float *output, const std::vector<int> &ranks_group,
|
||||
size_t data_num, const std::string &op_type);
|
||||
extern "C" FUNC_EXPORT bool MPIReduceScatterOverwriteInput(float *input, const std::vector<int> &ranks_group,
|
||||
size_t in_data_num, size_t output_size,
|
||||
const std::string &op_type, float *output);
|
||||
extern "C" FUNC_EXPORT bool MPIAllGather(const float *input, float *output, const std::vector<int> &ranks_group,
|
||||
size_t data_num);
|
||||
|
||||
#endif // MINDSPORE_CCSRC_RUNTIME_DEVICE_CPU_MPI_MPI_EXPORT_H_
|
@ -0,0 +1,85 @@
|
||||
/**
|
||||
* Copyright 2020 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* 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 "runtime/device/cpu/mpi/mpi_interface.h"
|
||||
#ifdef ENABLE_MPI
|
||||
#include <dlfcn.h>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "utils/log_adapter.h"
|
||||
|
||||
inline void *LoadLibrary(const char *name) {
|
||||
auto handle = dlopen(name, RTLD_LAZY | RTLD_LOCAL);
|
||||
if (handle == nullptr) {
|
||||
MS_LOG(EXCEPTION) << "Load lib " << name << " failed, make sure you have installed it!";
|
||||
}
|
||||
return handle;
|
||||
}
|
||||
|
||||
inline void *GetMPIAdapterHandle() {
|
||||
static void *handle = LoadLibrary("mpi_adapter.so");
|
||||
return handle;
|
||||
}
|
||||
|
||||
inline void *GetMPIAdapterFunc(const char *name) {
|
||||
static void *handle = GetMPIAdapterHandle();
|
||||
if (handle == nullptr) {
|
||||
MS_LOG(EXCEPTION) << "Load lib " << name << " failed, make sure you have installed it!";
|
||||
}
|
||||
void *func = dlsym(handle, name);
|
||||
if (func == nullptr) {
|
||||
MS_LOG(EXCEPTION) << "Load func " << name << " failed, make sure you have implied it!";
|
||||
}
|
||||
return func;
|
||||
}
|
||||
|
||||
typedef int (*GetMPIRankIdFunc)();
|
||||
typedef int (*GetMPIRankSizeFunc)();
|
||||
typedef bool (*MPIReduceScatterFunc)(const float *input, float *output, const std::vector<int> &ranks_group,
|
||||
size_t data_num, const std::string &op_type);
|
||||
typedef bool (*MPIReduceScatterOverwriteInputFunc)(float *input, const std::vector<int> &ranks_group,
|
||||
size_t in_data_num, size_t output_size, const std::string &op_type,
|
||||
float *output);
|
||||
typedef bool (*MPIAllGatherFunc)(const float *input, float *output, const std::vector<int> &ranks_group,
|
||||
size_t data_num);
|
||||
|
||||
int GetMPIRankId() {
|
||||
static GetMPIRankIdFunc func = reinterpret_cast<GetMPIRankIdFunc>(GetMPIAdapterFunc("GetMPIRankId"));
|
||||
return func();
|
||||
}
|
||||
|
||||
int GetMPIRankSize() {
|
||||
static GetMPIRankIdFunc func = reinterpret_cast<GetMPIRankSizeFunc>(GetMPIAdapterFunc("GetMPIRankSize"));
|
||||
return func();
|
||||
}
|
||||
|
||||
bool MPIReduceScatter(const float *input, float *output, const std::vector<int> &ranks_group, size_t data_num,
|
||||
const std::string &op_type) {
|
||||
static MPIReduceScatterFunc func = reinterpret_cast<MPIReduceScatterFunc>(GetMPIAdapterFunc("MPIReduceScatter"));
|
||||
return func(input, output, ranks_group, data_num, op_type);
|
||||
}
|
||||
|
||||
bool MPIReduceScatterOverwriteInput(float *input, const std::vector<int> &ranks_group, size_t in_data_num,
|
||||
size_t output_size, const std::string &op_type, float *output) {
|
||||
static MPIReduceScatterOverwriteInputFunc func =
|
||||
reinterpret_cast<MPIReduceScatterOverwriteInputFunc>(GetMPIAdapterFunc("MPIReduceScatterOverwriteInput"));
|
||||
return func(input, ranks_group, in_data_num, output_size, op_type, output);
|
||||
}
|
||||
|
||||
bool MPIAllGather(const float *input, float *output, const std::vector<int> &ranks_group, size_t data_num) {
|
||||
static MPIAllGatherFunc func = reinterpret_cast<MPIAllGatherFunc>(GetMPIAdapterFunc("MPIAllGather"));
|
||||
return func(input, output, ranks_group, data_num);
|
||||
}
|
||||
#endif // ENABLE_MPI
|
@ -0,0 +1,34 @@
|
||||
/**
|
||||
* Copyright 2020 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef MINDSPORE_CCSRC_RUNTIME_DEVICE_CPU_MPI_MPI_INTERFACE_H_
|
||||
#define MINDSPORE_CCSRC_RUNTIME_DEVICE_CPU_MPI_MPI_INTERFACE_H_
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#ifndef FUNC_EXPORT
|
||||
#define FUNC_EXPORT __attribute__((visibility("default")))
|
||||
#endif
|
||||
constexpr auto kMPIOpTypeSum = "sum";
|
||||
#ifdef ENABLE_MPI
|
||||
int GetMPIRankId();
|
||||
int GetMPIRankSize();
|
||||
bool MPIReduceScatter(const float *input, float *output, const std::vector<int> &ranks_group, size_t data_num,
|
||||
const std::string &op_type = kMPIOpTypeSum);
|
||||
bool MPIReduceScatterOverwriteInput(float *input, const std::vector<int> &ranks_group, size_t in_data_num,
|
||||
size_t output_size, const std::string &op_type = kMPIOpTypeSum,
|
||||
float *output = nullptr);
|
||||
bool MPIAllGather(const float *input, float *output, const std::vector<int> &ranks_group, size_t data_num);
|
||||
#endif // ENABLE_MPI
|
||||
#endif // MINDSPORE_CCSRC_RUNTIME_DEVICE_CPU_MPI_MPI_INTERFACE_H_
|
Loading…
Reference in new issue