Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/excuter/op-mem-ompsimd/list.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
|-----------|--------|------------|--------------|----------------|
| reducemax | miaobyte | reducemax(tensor<any> A, vector<int32> axis, var<bool> keepdims)->(tensor<any> B) | B = reducemax(A, axis=[1 2], keepdims=false) | reducemax(tensor<any> A, vector<int32> axis, var<bool> keepdims)->(tensor<any> B) |
| broadcastTo | miaobyte | broadcastTo(tensor<any> A, vector<int32> new_shape)->(tensor<any> B) | T2 = T1.broadcastTo(new_shape=[4,3,2]) | broadcastTo(tensor<any> A, vector<int32> new_shape)->(tensor<any> B) |
| concat | miaobyte | concat(listtensor<any> tensors, var<int32> axis)->(tensor<any> result) | Tresult = concat([T1, T2...], axis=3) | concat(listtensor<any> tensors, var<int32> axis)->(tensor<any> result) |
| concat | miaobyte | concat(listtensor<any> tensors, var<int32> dim)->(tensor<any> result) | Tresult = concat([T1, T2...], axis=3) | concat(listtensor<any> tensors, var<int32> dim)->(tensor<any> result) |
| transpose | miaobyte | transpose(tensor<any> A, vector<int32> dim_order)->(tensor<any> C) | T1.transpose(dimorder=[1,0])->T2 | transpose(tensor<any> A, vector<int32> dim_order)->(tensor<any> C) |
| add | cblas | add(tensor<float64|float32> a, tensor<float64|float32> b)->(tensor<float64|float32> c) | T3=T1+T2 | add(tensor<float64|float32> a, tensor<float64|float32> b)->(tensor<float64|float32> c) |
| add | miaobyte | add(tensor<any> a, tensor<any> b)->(tensor<any> c) | T3=T1+T2 | add(tensor<any> a, tensor<any> b)->(tensor<any> c) |
Expand Down
99 changes: 98 additions & 1 deletion excuter/cpp-common/src/deepx/dtype.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@
#include <string>
#include <cstdint>
#include <sstream>
#include <vector>
#include "stdutil/string.hpp"
#include "stdutil/num.hpp"

namespace deepx
{
using namespace std;

template <typename T>
T to(const std::string &textvalue)
{
Expand Down Expand Up @@ -134,7 +139,7 @@ namespace deepx
Bool = 1 << 13, // 0010 0000 0000 0000
String = 1 << 15, // 0100 0000 0000 0000
// 常用组合
Any = 0xFFFF, // 1111 1111 1111 1111
Any = 0xFFFF, // 1111 1111 1111 1111
Float = Float64 | Float32 | Float16 | BFloat16 | Float8E5M2 | Float8E4M3 | Float4E2M1,
Float8 = Float8E5M2 | Float8E4M3, // 所有FP8格式
Int = Int64 | Int32 | Int16 | Int8 | Int4
Expand Down Expand Up @@ -372,5 +377,97 @@ namespace deepx
precision(precision_str));
}

inline TypeDef autodtype(const std::string &param)
{
std::string type;
std::string textvalue;
std::vector<std::string> vectorvalues;
bool vectorvalue = false;
if (param.back() == ']')
{
size_t bracket_start = param.find('[');
if (bracket_start != string::npos)
{
vectorvalue = true;
// 提取方括号内的内容作为textvalue
textvalue = param.substr(bracket_start + 1, param.length() - bracket_start - 2);
// 提取方括号前的内容作为type
type = param.substr(0, bracket_start);
// 去除type两端的空格
stdutil::trim(type);
}
}

if (!vectorvalue)
{
// 没有方括号,按空格分割
stringstream ss(param);
string first, second;
ss >> first;
if (ss >> second)
{
// 如果能读取到两个部分
type = first;
textvalue = second;
}
else
{
textvalue = first;
}
}
// 处理向量值
if (vectorvalue)
{
// 分割字符串为向量
stringstream ss(textvalue);
string item;
while (getline(ss, item, ' '))
{
item.erase(0, item.find_first_not_of(" "));
item.erase(item.find_last_not_of(" ") + 1);
if (!item.empty())
{
vectorvalues.push_back(item);
}
}
}

// 设置结果
if (!type.empty())
{
return dtype(type);
}
else
{
// 没有显式类型声明,根据值推断
if (vectorvalue)
{
if (!vectorvalues.empty())
{
if (is_integer(vectorvalues[0]))
{
return make_dtype(DataCategory::Vector, Precision::Int32);
}
else if (is_float(vectorvalues[0]))
{
return make_dtype(DataCategory::Vector, Precision::Float64);
}
else
{
return make_dtype(DataCategory::ListTensor, Precision::Any);
}
}
else
{
return make_dtype(DataCategory::Vector, Precision::Any);
}
}
else
{
return make_dtype(DataCategory::Var | DataCategory::Tensor, Precision::Any);
}
}
}

} // namespace deepx
#endif
9 changes: 0 additions & 9 deletions excuter/cpp-common/src/deepx/tf/arg.hpp

This file was deleted.

9 changes: 0 additions & 9 deletions excuter/cpp-common/src/deepx/tf/new.hpp

This file was deleted.

159 changes: 44 additions & 115 deletions excuter/cpp-common/src/deepx/tf/tf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,41 @@

#include "deepx/tf/tf.hpp"
#include "stdutil/time.hpp"
#include "stdutil/string.hpp"
namespace deepx::tf
{
{


void Param::parse(const string &param)
{
//1. 按:分割类型和值
size_t colon_pos = param.find(':');
string type, textvalue;
if (colon_pos != string::npos)
{
type = param.substr(0, colon_pos);
stdutil::trimspace(type);
textvalue = param.substr(colon_pos + 1);
stdutil::trimspace(textvalue);
}
else
{
textvalue = param;
stdutil::trimspace(textvalue);
}
if (!type.empty())
{
this->dtype = deepx::dtype(type);
this->textvalue = textvalue;
}
else
{
this->dtype = deepx::dtype(textvalue);
this->textvalue = textvalue;
}

}
// 分割主体和元数据
std::pair<string, string> split_body_metadata(const string &input)
{
size_t meta_pos = input.find("//");
Expand All @@ -30,11 +63,14 @@ namespace deepx::tf
size_t space_pos = input_part.find(' ');
size_t paren_pos = input_part.find('(');
size_t name_end;

if (paren_pos != string::npos && (space_pos == string::npos || paren_pos < space_pos)) {

if (paren_pos != string::npos && (space_pos == string::npos || paren_pos < space_pos))
{
// 如果有括号且括号在空格之前,使用括号位置
name_end = paren_pos;
} else {
}
else
{
// 否则使用空格位置或字符串末尾
name_end = space_pos != string::npos ? space_pos : input_part.length();
}
Expand Down Expand Up @@ -150,112 +186,7 @@ namespace deepx::tf
return value_str; // 默认作为字符串处理
}

// 主参数解析函数,param已经去除两侧空格
Param parse_param(const string &param)
{
Param result;
if (param.empty())
{
return result;
}

// 初始化变量
string type;
string textvalue;
vector<string> vectorvalues;
bool vectorvalue = false;

// 检查是否是向量值(以]结尾)
if (param.back() == ']')
{
size_t bracket_start = param.find_last_of('[');
if (bracket_start != string::npos)
{
vectorvalue = true;
// 提取方括号内的内容作为textvalue
textvalue = param.substr(bracket_start + 1, param.length() - bracket_start - 2);
// 提取方括号前的内容作为type
type = param.substr(0, bracket_start);
// 去除type两端的空格
type.erase(0, type.find_first_not_of(" "));
type.erase(type.find_last_not_of(" ") + 1);
}
}

if (!vectorvalue)
{
// 没有方括号,按空格分割
stringstream ss(param);
string first, second;
ss >> first;
if (ss >> second)
{
// 如果能读取到两个部分
type = first;
textvalue = second;
}
else
{
textvalue = first;
}
}

// 处理向量值
if (vectorvalue)
{
// 分割字符串为向量
stringstream ss(textvalue);
string item;
while (getline(ss, item, ' '))
{
item.erase(0, item.find_first_not_of(" "));
item.erase(item.find_last_not_of(" ") + 1);
if (!item.empty())
{
vectorvalues.push_back(item);
}
}
}

// 设置结果
if (!type.empty())
{
result.dtype = dtype(type);
}
else
{
// 没有显式类型声明,根据值推断
if (vectorvalue)
{
if (!vectorvalues.empty())
{
if (is_integer(vectorvalues[0])){
result.dtype = make_dtype(DataCategory::Vector, Precision::Int32);
}
else if (is_float(vectorvalues[0]))
{
result.dtype = make_dtype(DataCategory::Vector, Precision::Float64);
}
else
{
result.dtype = make_dtype(DataCategory::ListTensor, Precision::Any);
}
}
else
{
result.dtype = make_dtype(DataCategory::Vector, Precision::Any);
}
}
else
{
result.dtype = make_dtype(DataCategory::Var|DataCategory::Tensor, Precision::Any);
}
}

result.textvalue = textvalue;
return result;
}


// 解析参数列表
vector<Param> parse_params(const string &params_str)
{
Expand All @@ -266,14 +197,14 @@ namespace deepx::tf
while (getline(params_ss, param, ','))
{
// 去除首尾空格
param.erase(0, param.find_first_not_of(" "));
param.erase(param.find_last_not_of(" ") + 1);
stdutil::trimspace(param);

if (param.empty())
continue;

// 解析单个参数
Param parsed_param = parse_param(param);
Param parsed_param;
parsed_param.parse(param);
params.push_back(parsed_param);
}

Expand Down Expand Up @@ -452,6 +383,4 @@ namespace deepx::tf
return true;
}



}
Loading