@@ -1,39 +0,0 @@ | |||||
/** | |||||
* Copyright 2019-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 INC_REGISTER_HOST_CPU_CONTEXT_H_ | |||||
#define INC_REGISTER_HOST_CPU_CONTEXT_H_ | |||||
#include "external/ge/ge_api_error_codes.h" | |||||
#include "register/register_types.h" | |||||
namespace ge { | |||||
class HostCpuContext { | |||||
public: | |||||
HostCpuContext() = default; | |||||
~HostCpuContext() = default; | |||||
private: | |||||
class Impl; | |||||
Impl *impl_; | |||||
}; | |||||
} // namespace ge | |||||
extern "C" { | |||||
// Unified definition for registering host_cpu_kernel_wrapper when so is opened | |||||
FMK_FUNC_HOST_VISIBILITY ge::Status Initialize(const ge::HostCpuContext &ctx); | |||||
} | |||||
#endif //INC_REGISTER_HOST_CPU_CONTEXT_H_ |
@@ -1,49 +0,0 @@ | |||||
/** | |||||
* Copyright 2019-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 INC_REGISTER_OP_KERNEL_REGISTRY_H_ | |||||
#define INC_REGISTER_OP_KERNEL_REGISTRY_H_ | |||||
#include <memory> | |||||
#include <string> | |||||
#include "register/register_types.h" | |||||
#include "register.h" | |||||
namespace ge { | |||||
class FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY OpKernelRegistry { | |||||
public: | |||||
using CreateFn = HostCpuOp* (*)(); | |||||
~OpKernelRegistry(); | |||||
static OpKernelRegistry& GetInstance() { | |||||
static OpKernelRegistry instance; | |||||
return instance; | |||||
} | |||||
bool IsRegistered(const std::string &op_type); | |||||
void RegisterHostCpuOp(const std::string &op_type, CreateFn create_fn); | |||||
std::unique_ptr<HostCpuOp> CreateHostCpuOp(const std::string &op_type); | |||||
private: | |||||
OpKernelRegistry(); | |||||
class OpKernelRegistryImpl; | |||||
/*lint -e148*/ | |||||
std::unique_ptr<OpKernelRegistryImpl> impl_; | |||||
}; | |||||
} // namespace ge | |||||
#endif // INC_REGISTER_OP_KERNEL_REGISTRY_H_ |
@@ -1,90 +0,0 @@ | |||||
/** | |||||
* Copyright 2019-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 INC_REGISTER_OP_REGISTRY_H_ | |||||
#define INC_REGISTER_OP_REGISTRY_H_ | |||||
#include <limits.h> | |||||
#include <set> | |||||
#include <string> | |||||
#include <unordered_map> | |||||
#include <vector> | |||||
#include "register/register.h" | |||||
namespace domi { | |||||
enum RemoveInputType { | |||||
OMG_MOVE_TYPE_DTYPE = 0, | |||||
OMG_MOVE_TYPE_VALUE, | |||||
OMG_MOVE_TYPE_SHAPE, | |||||
OMG_MOVE_TYPE_FORMAT, | |||||
OMG_MOVE_TYPE_AXIS, | |||||
OMG_MOVE_TYPE_SCALAR_VALUE, | |||||
OMG_REMOVE_TYPE_WITH_COND = 1000, | |||||
OMG_REMOVE_INPUT_WITH_ORIGINAL_TYPE, | |||||
OMG_INPUT_REORDER, | |||||
}; | |||||
struct RemoveInputConfigure { | |||||
int inputIdx = INT_MAX; | |||||
std::string attrName; | |||||
RemoveInputType moveType; | |||||
bool attrValue = false; | |||||
std::string originalType; | |||||
std::vector<int> input_order; | |||||
}; | |||||
class FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY OpRegistry { | |||||
public: | |||||
static OpRegistry *Instance(); | |||||
std::vector<OpRegistrationData> registrationDatas; | |||||
bool Register(const OpRegistrationData ®_data); | |||||
domi::ImplyType GetImplyType(const std::string &op_type); | |||||
void GetOpTypeByImplyType(std::vector<std::string> &vec_op_type, const domi::ImplyType &imply_type); | |||||
domi::ParseParamFunc GetParseParamFunc(const std::string &op_type, const std::string &ori_type); | |||||
domi::ParseParamByOpFunc GetParseParamByOperatorFunc(const std::string &ori_type); | |||||
domi::FusionParseParamFunc GetFusionParseParamFunc(const std::string &op_type, const std::string &ori_type); | |||||
domi::FusionParseParamByOpFunc GetFusionParseParamByOpFunc(const std::string &op_type, | |||||
const std::string &ori_type); | |||||
domi::ParseSubgraphFunc GetParseSubgraphPostFunc(const std::string &op_type); | |||||
domi::ImplyType GetImplyTypeByOriOpType(const std::string &ori_optype); | |||||
const std::vector<RemoveInputConfigure> &GetRemoveInputConfigure(const std::string &ori_optype) const; | |||||
bool GetOmTypeByOriOpType(const std::string &ori_optype, std::string &om_type); | |||||
private: | |||||
std::unordered_map<std::string, domi::ImplyType> op_run_mode_map_; | |||||
std::unordered_map<std::string, ParseParamFunc> op_parse_params_fn_map_; | |||||
std::unordered_map<std::string, ParseParamByOpFunc> parse_params_by_op_func_map_; | |||||
std::unordered_map<std::string, FusionParseParamFunc> fusion_op_parse_params_fn_map_; | |||||
std::unordered_map<std::string, FusionParseParamByOpFunc> fusion_parse_params_by_op_fn_map_; | |||||
std::unordered_map<std::string, ParseSubgraphFunc> op_types_to_parse_subgraph_post_func_; | |||||
std::unordered_map<std::string, std::vector<RemoveInputConfigure>> remove_input_configure_map_; | |||||
std::unordered_map<std::string, std::string> origin_type_to_om_type_; | |||||
}; | |||||
} // namespace domi | |||||
#endif // INC_REGISTER_OP_REGISTRY_H_ |
@@ -1,135 +0,0 @@ | |||||
/** | |||||
* Copyright 2019-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 INC_OP_TILING_H_ | |||||
#define INC_OP_TILING_H_ | |||||
#include "external/register/register_types.h" | |||||
#include "external/graph/tensor.h" | |||||
#include "graph/debug/ge_attr_define.h" | |||||
#include "graph/node.h" | |||||
#include <nlohmann/json.hpp> | |||||
#include <iostream> | |||||
#include <sstream> | |||||
#include <functional> | |||||
#include <vector> | |||||
#include <map> | |||||
#include <string> | |||||
#include "graph/node.h" | |||||
#define REGISTER_OP_TILING_FUNC(optype, opfunc) \ | |||||
REGISTER_OP_TILING_FUNC_UNIQ_HELPER(optype, opfunc, __COUNTER__) | |||||
#define REGISTER_OP_TILING_FUNC_UNIQ_HELPER(optype, opfunc, counter) \ | |||||
REGISTER_OP_TILING_FUNC_UNIQ(optype, opfunc, counter) | |||||
#define REGISTER_OP_TILING_FUNC_UNIQ(optype, opfunc, counter) \ | |||||
static OpTilingInterf g_##optype##TilingInterf##counter(#optype, opfunc) | |||||
namespace optiling { | |||||
enum TensorArgType { | |||||
TA_NONE, | |||||
TA_SINGLE, | |||||
TA_LIST, | |||||
}; | |||||
using ByteBuffer = std::stringstream; | |||||
struct TeOpTensor { | |||||
std::vector<int64_t> shape; | |||||
std::vector<int64_t> ori_shape; | |||||
std::string format; | |||||
std::string ori_format; | |||||
std::string dtype; | |||||
std::map<std::string, std::string> attrs; | |||||
}; | |||||
struct TeOpTensorArg { | |||||
TensorArgType arg_type; | |||||
std::vector<TeOpTensor> tensor; | |||||
}; | |||||
struct OpRunInfo { | |||||
uint32_t block_dim; | |||||
std::vector<int64_t> workspaces; | |||||
ByteBuffer tiling_data; | |||||
}; | |||||
using TeOpAttrArgs = std::vector<std::string>; | |||||
using TeConstTensorData = std::tuple<const uint8_t*, size_t, ge::Tensor>; | |||||
struct TeOpParas { | |||||
std::vector<TeOpTensorArg> inputs; | |||||
std::vector<TeOpTensorArg> outputs; | |||||
std::map<std::string, TeConstTensorData> const_inputs; | |||||
TeOpAttrArgs attrs; | |||||
}; | |||||
using OpTilingFunc = std::function<bool(const std::string&, const TeOpParas&, | |||||
const nlohmann::json& , OpRunInfo&)>; | |||||
using OpTilingFuncPtr = bool(*)(const std::string&, const TeOpParas&, const nlohmann::json& , OpRunInfo&); | |||||
class FMK_FUNC_HOST_VISIBILITY OpTilingInterf | |||||
{ | |||||
public: | |||||
OpTilingInterf(std::string op_type, OpTilingFunc func); | |||||
~OpTilingInterf() = default; | |||||
static std::map<std::string, OpTilingFunc> &RegisteredOpInterf(); | |||||
static std::string OpTilingUuid; | |||||
}; | |||||
template <class T> | |||||
ByteBuffer& ByteBufferPut(ByteBuffer &buf, const T &value) | |||||
{ | |||||
buf.write(reinterpret_cast<const char*>(&value), sizeof(value)); | |||||
buf.flush(); | |||||
return buf; | |||||
} | |||||
template <class T> | |||||
ByteBuffer& ByteBufferGet(ByteBuffer &buf, T &value) | |||||
{ | |||||
buf.read(reinterpret_cast<char*>(&value), sizeof(value)); | |||||
return buf; | |||||
} | |||||
inline size_t ByteBufferGetAll(ByteBuffer &buf, char *dest, size_t dest_len) | |||||
{ | |||||
size_t nread = 0; | |||||
size_t rn = 0; | |||||
do { | |||||
rn = buf.readsome(dest + nread, dest_len - nread); | |||||
nread += rn; | |||||
} while (rn > 0 && dest_len > nread); | |||||
return nread; | |||||
} | |||||
extern "C" ge::graphStatus OpParaCalculate(const ge::Node &node, OpRunInfo &run_info); | |||||
extern "C" ge::graphStatus OpAtomicCalculate(const ge::Node &node, OpRunInfo &run_info); | |||||
} | |||||
#endif // INC_OP_TILING_H_ |
@@ -1,62 +0,0 @@ | |||||
/** | |||||
* Copyright 2019-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 INC_REGISTER_OPS_KERNEL_BUILDER_REGISTRY_H_ | |||||
#define INC_REGISTER_OPS_KERNEL_BUILDER_REGISTRY_H_ | |||||
#include <memory> | |||||
#include "register/register_types.h" | |||||
#include "common/opskernel/ops_kernel_builder.h" | |||||
namespace ge { | |||||
using OpsKernelBuilderPtr = std::shared_ptr<OpsKernelBuilder>; | |||||
class FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY OpsKernelBuilderRegistry { | |||||
public: | |||||
static OpsKernelBuilderRegistry &GetInstance(); | |||||
void Register(const std::string &lib_name, const OpsKernelBuilderPtr &instance); | |||||
void UnregisterAll(); | |||||
const std::map<std::string, OpsKernelBuilderPtr> &GetAll() const; | |||||
private: | |||||
std::map<std::string, OpsKernelBuilderPtr> kernel_builders_; | |||||
}; | |||||
class FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY OpsKernelBuilderRegistrar { | |||||
public: | |||||
using CreateFn = OpsKernelBuilder *(*)(); | |||||
OpsKernelBuilderRegistrar(const std::string &kernel_lib_name, CreateFn fn); | |||||
~OpsKernelBuilderRegistrar() = default; | |||||
}; | |||||
#define REGISTER_OPS_KERNEL_BUILDER(kernel_lib_name, builder) \ | |||||
REGISTER_OPS_KERNEL_BUILDER_UNIQ_HELPER(__COUNTER__, kernel_lib_name, builder) | |||||
#define REGISTER_OPS_KERNEL_BUILDER_UNIQ_HELPER(ctr, kernel_lib_name, builder) \ | |||||
REGISTER_OPS_KERNEL_BUILDER_UNIQ(ctr, kernel_lib_name, builder) | |||||
#define REGISTER_OPS_KERNEL_BUILDER_UNIQ(ctr, kernel_lib_name, builder) \ | |||||
static ::ge::OpsKernelBuilderRegistrar register_op_kernel_builder_##ctr \ | |||||
__attribute__((unused)) = \ | |||||
::ge::OpsKernelBuilderRegistrar(kernel_lib_name, []()->::ge::OpsKernelBuilder* { \ | |||||
return new (std::nothrow) builder(); \ | |||||
}) | |||||
} // namespace ge | |||||
#endif // INC_REGISTER_OPS_KERNEL_BUILDER_REGISTRY_H_ |
@@ -1,54 +0,0 @@ | |||||
/** | |||||
* Copyright 2019-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 INC_REGISTER_REGISTRY_H_ | |||||
#define INC_REGISTER_REGISTRY_H_ | |||||
#include "external/register/register.h" | |||||
#include "external/ge/ge_api_error_codes.h" | |||||
namespace ge { | |||||
class FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY HostCpuOp { | |||||
public: | |||||
HostCpuOp() = default; | |||||
virtual ~HostCpuOp() = default; | |||||
virtual graphStatus Compute(Operator &op, | |||||
const std::map<std::string, const Tensor> &inputs, | |||||
std::map<std::string, Tensor> &outputs) = 0; | |||||
}; | |||||
class FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY HostCpuOpRegistrar { | |||||
public: | |||||
HostCpuOpRegistrar(const char *op_type, HostCpuOp *(*create_fn)()); | |||||
~HostCpuOpRegistrar() = default; | |||||
}; | |||||
#define REGISTER_HOST_CPU_OP_BUILDER(name, op) \ | |||||
REGISTER_HOST_CPU_OP_BUILDER_UNIQ_HELPER(__COUNTER__, name, op) | |||||
#define REGISTER_HOST_CPU_OP_BUILDER_UNIQ_HELPER(ctr, name, op) \ | |||||
REGISTER_HOST_CPU_OP_BUILDER_UNIQ(ctr, name, op) | |||||
#define REGISTER_HOST_CPU_OP_BUILDER_UNIQ(ctr, name, op) \ | |||||
static ::ge::HostCpuOpRegistrar register_host_cpu_op##ctr \ | |||||
__attribute__((unused)) = \ | |||||
::ge::HostCpuOpRegistrar(name, []()->::ge::HostCpuOp* { \ | |||||
return new (std::nothrow) op(); \ | |||||
}) | |||||
} // namespace ge | |||||
#endif //INC_REGISTER_REGISTRY_H_ |
@@ -1,79 +0,0 @@ | |||||
/** | |||||
* Copyright 2019-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 INC_REGISTER_REGISTER_FORMAT_TRANSFER_H_ | |||||
#define INC_REGISTER_REGISTER_FORMAT_TRANSFER_H_ | |||||
#include <functional> | |||||
#include <memory> | |||||
#include <vector> | |||||
#include "external/graph/types.h" | |||||
#include "ge/ge_api_error_codes.h" | |||||
namespace ge { | |||||
namespace formats { | |||||
struct TransArgs { | |||||
const uint8_t *data; | |||||
Format src_format; | |||||
Format dst_format; | |||||
// For scenes that need to supplement the shape, for example, 5D to 4D | |||||
// It is not possible to convert the format normally if you only get the src_shape, | |||||
// and must get the shape before you mend the shape. | |||||
// So the parameters here need to be passed in both src_shape and dst_shape | |||||
std::vector<int64_t> src_shape; | |||||
std::vector<int64_t> dst_shape; | |||||
DataType src_data_type; | |||||
}; | |||||
struct TransResult { | |||||
std::shared_ptr<uint8_t> data; | |||||
// data length in bytes | |||||
size_t length; | |||||
}; | |||||
class FormatTransfer { | |||||
public: | |||||
virtual ~FormatTransfer() = default; | |||||
virtual Status TransFormat(const TransArgs &args, TransResult &result) = 0; | |||||
virtual Status TransShape(Format src_format, const std::vector<int64_t> &src_shape, DataType data_type, | |||||
Format dst_format, std::vector<int64_t> &dst_shape) = 0; | |||||
}; | |||||
using FormatTransferBuilder = std::function<std::shared_ptr<FormatTransfer>()>; | |||||
class FormatTransferRegister { | |||||
public: | |||||
FormatTransferRegister(FormatTransferBuilder builder, Format src, Format dst); | |||||
~FormatTransferRegister() = default; | |||||
}; | |||||
#define REGISTER_FORMAT_TRANSFER(TransferClass, format1, format2) \ | |||||
namespace { \ | |||||
FormatTransferRegister format_transfer_register_##TransferClass##format1##format2( \ | |||||
[]() { return std::make_shared<TransferClass>(); }, format1, format2); \ | |||||
} | |||||
/// Build a formattransfer according to 'args' | |||||
/// @param args | |||||
/// @param result | |||||
/// @return | |||||
std::shared_ptr<FormatTransfer> BuildFormatTransfer(const TransArgs &args); | |||||
bool FormatTransferExists(const TransArgs &args); | |||||
} // namespace formats | |||||
} // namespace ge | |||||
#endif // INC_REGISTER_REGISTER_FORMAT_TRANSFER_H_ |