|
|
@ -19,135 +19,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
#include <functional>
|
|
|
|
#include <functional>
|
|
|
|
#include <map>
|
|
|
|
#include <map>
|
|
|
|
#include <nlohmann/json.hpp>
|
|
|
|
|
|
|
|
#include <sstream>
|
|
|
|
#include <sstream>
|
|
|
|
#include <string>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
#include <vector>
|
|
|
|
#include "external/register/register_types.h"
|
|
|
|
#include "external/register/register_types.h"
|
|
|
|
#include "external/graph/tensor.h"
|
|
|
|
#include "external/graph/tensor.h"
|
|
|
|
|
|
|
|
|
|
|
|
#define REGISTER_OP_TILING_FUNC(optype, opfunc) \
|
|
|
|
#define REGISTER_OP_TILING(optype, opfunc) REGISTER_OP_TILING_UNIQ_HELPER(optype, opfunc, __COUNTER__)
|
|
|
|
REGISTER_OP_TILING_FUNC_UNIQ_HELPER(optype, opfunc, __COUNTER__)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define REGISTER_OP_TILING_FUNC_UNIQ_HELPER(optype, opfunc, counter) \
|
|
|
|
#define REGISTER_OP_TILING_FUNC_NEW(optype, opfunc) REGISTER_OP_TILING_UNIQ_HELPER(optype, opfunc, __COUNTER__)
|
|
|
|
REGISTER_OP_TILING_FUNC_UNIQ(optype, opfunc, counter)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define REGISTER_OP_TILING_FUNC_UNIQ(optype, opfunc, counter) \
|
|
|
|
#define REGISTER_OP_TILING_UNIQ_HELPER(optype, opfunc, counter) REGISTER_OP_TILING_UNIQ(optype, opfunc, counter)
|
|
|
|
static OpTilingInterf g_##optype##TilingInterf##counter(#optype, opfunc)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define REGISTER_OP_TILING_FUNC_NEW(optype, opfunc) \
|
|
|
|
#define REGISTER_OP_TILING_UNIQ(optype, opfunc, counter) \
|
|
|
|
REGISTER_OP_TILING_UNIQ_HELPER(optype, opfunc, __COUNTER__)
|
|
|
|
static OpTilingRegistryInterf g_##optype##TilingRegistryInterf##counter(#optype, opfunc)
|
|
|
|
|
|
|
|
|
|
|
|
#define REGISTER_OP_TILING(optype, opfunc) \
|
|
|
|
|
|
|
|
REGISTER_OP_TILING_UNIQ_HELPER(optype, opfunc, __COUNTER__)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define REGISTER_OP_TILING_UNIQ_HELPER(optype, opfunc, counter) \
|
|
|
|
|
|
|
|
REGISTER_OP_TILING_UNIQ(optype, opfunc, counter)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define REGISTER_OP_TILING_UNIQ(optype, opfunc, counter) \
|
|
|
|
|
|
|
|
static OpTilingRegistryInterf g_##optype##TilingRegistryInterf##counter(#optype, opfunc)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace optiling {
|
|
|
|
namespace optiling {
|
|
|
|
|
|
|
|
|
|
|
|
enum TensorArgType {
|
|
|
|
enum TensorArgType {
|
|
|
|
TA_NONE,
|
|
|
|
TA_NONE,
|
|
|
|
TA_SINGLE,
|
|
|
|
TA_SINGLE,
|
|
|
|
TA_LIST,
|
|
|
|
TA_LIST,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
using ByteBuffer = std::stringstream;
|
|
|
|
using ByteBuffer = std::stringstream;
|
|
|
|
|
|
|
|
|
|
|
|
struct TeOpTensor {
|
|
|
|
struct TeOpTensor {
|
|
|
|
std::vector<int64_t> shape;
|
|
|
|
std::vector<int64_t> shape;
|
|
|
|
std::vector<int64_t> ori_shape;
|
|
|
|
std::vector<int64_t> ori_shape;
|
|
|
|
std::string format;
|
|
|
|
std::string format;
|
|
|
|
std::string ori_format;
|
|
|
|
std::string ori_format;
|
|
|
|
std::string dtype;
|
|
|
|
std::string dtype;
|
|
|
|
std::map<std::string, std::string> attrs;
|
|
|
|
std::map<std::string, std::string> attrs;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct TeOpTensorArg {
|
|
|
|
struct TeOpTensorArg {
|
|
|
|
TensorArgType arg_type;
|
|
|
|
TensorArgType arg_type;
|
|
|
|
std::vector<TeOpTensor> tensor;
|
|
|
|
std::vector<TeOpTensor> tensor;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct OpRunInfo {
|
|
|
|
struct OpRunInfo {
|
|
|
|
uint32_t block_dim;
|
|
|
|
uint32_t block_dim;
|
|
|
|
std::vector<int64_t> workspaces;
|
|
|
|
std::vector<int64_t> workspaces;
|
|
|
|
ByteBuffer tiling_data;
|
|
|
|
ByteBuffer tiling_data;
|
|
|
|
bool clear_atomic;
|
|
|
|
bool clear_atomic;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using TeOpAttrArgs = std::vector<std::string>;
|
|
|
|
using TeOpAttrArgs = std::vector<std::string>;
|
|
|
|
using TeConstTensorData = std::tuple<const uint8_t*, size_t, ge::Tensor>;
|
|
|
|
using TeConstTensorData = std::tuple<const uint8_t *, size_t, ge::Tensor>;
|
|
|
|
|
|
|
|
|
|
|
|
struct TeOpParas {
|
|
|
|
struct TeOpParas {
|
|
|
|
std::vector<TeOpTensorArg> inputs;
|
|
|
|
std::vector<TeOpTensorArg> inputs;
|
|
|
|
std::vector<TeOpTensorArg> outputs;
|
|
|
|
std::vector<TeOpTensorArg> outputs;
|
|
|
|
std::map<std::string, TeConstTensorData> const_inputs;
|
|
|
|
std::map<std::string, TeConstTensorData> const_inputs;
|
|
|
|
TeOpAttrArgs attrs;
|
|
|
|
TeOpAttrArgs attrs;
|
|
|
|
std::string op_type;
|
|
|
|
std::string op_type;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct OpCompileInfo {
|
|
|
|
struct OpCompileInfo {
|
|
|
|
std::string str;
|
|
|
|
std::string str;
|
|
|
|
std::string key;
|
|
|
|
std::string key;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
using OpTilingFuncNew = std::function<bool(const TeOpParas&, const OpCompileInfo& , OpRunInfo&)>;
|
|
|
|
using OpTilingFunc = std::function<bool(const TeOpParas &, const OpCompileInfo &, OpRunInfo &)>;
|
|
|
|
|
|
|
|
|
|
|
|
using OpTilingFuncPtrNew = bool(*)(const TeOpParas&, const OpCompileInfo& , OpRunInfo&);
|
|
|
|
using OpTilingFuncPtr = bool (*)(const TeOpParas &, const OpCompileInfo &, OpRunInfo &);
|
|
|
|
|
|
|
|
|
|
|
|
class FMK_FUNC_HOST_VISIBILITY OpTilingRegistryInterf {
|
|
|
|
class FMK_FUNC_HOST_VISIBILITY OpTilingRegistryInterf {
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
OpTilingRegistryInterf(std::string op_type, OpTilingFuncNew func);
|
|
|
|
OpTilingRegistryInterf(std::string op_type, OpTilingFunc func);
|
|
|
|
~OpTilingRegistryInterf() = default;
|
|
|
|
~OpTilingRegistryInterf() = default;
|
|
|
|
static std::map<std::string, OpTilingFuncNew> &RegisteredOpInterf();
|
|
|
|
static std::map<std::string, OpTilingFunc> &RegisteredOpInterf();
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
template <class T>
|
|
|
|
ByteBuffer& ByteBufferPut(ByteBuffer &buf, const T &value)
|
|
|
|
ByteBuffer &ByteBufferPut(ByteBuffer &buf, const T &value) {
|
|
|
|
{
|
|
|
|
buf.write(reinterpret_cast<const char *>(&value), sizeof(value));
|
|
|
|
buf.write(reinterpret_cast<const char*>(&value), sizeof(value));
|
|
|
|
buf.flush();
|
|
|
|
buf.flush();
|
|
|
|
return buf;
|
|
|
|
return buf;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
template <class T>
|
|
|
|
ByteBuffer& ByteBufferGet(ByteBuffer &buf, T &value)
|
|
|
|
ByteBuffer &ByteBufferGet(ByteBuffer &buf, T &value) {
|
|
|
|
{
|
|
|
|
buf.read(reinterpret_cast<char *>(&value), sizeof(value));
|
|
|
|
buf.read(reinterpret_cast<char*>(&value), sizeof(value));
|
|
|
|
return buf;
|
|
|
|
return buf;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline size_t ByteBufferGetAll(ByteBuffer &buf, char *dest, size_t dest_len)
|
|
|
|
size_t ByteBufferGetAll(ByteBuffer &buf, char *dest, size_t dest_len);
|
|
|
|
{
|
|
|
|
} // namespace optiling
|
|
|
|
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;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif // INC_REGISTER_OP_TILING_REGISTRY_H_
|
|
|
|
#endif // INC_REGISTER_OP_TILING_REGISTRY_H_
|
|
|
|