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
9 changes: 5 additions & 4 deletions src/backend/common/jit/BufferNodeBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,12 @@ class BufferNodeBase : public common::Node {
return m_linear_buffer && same_dims;
}

void genKerName(std::stringstream &kerStream,
void genKerName(std::string &kerString,
const common::Node_ids &ids) const final {
kerStream << "_" << getNameStr();
kerStream << std::setw(3) << std::setfill('0') << std::dec << ids.id
<< std::dec;
kerString += '_';
Comment thread
willyborn marked this conversation as resolved.
kerString += getNameStr();
kerString += ',';
kerString += std::to_string(ids.id);
}

void genParams(std::stringstream &kerStream, int id,
Expand Down
14 changes: 7 additions & 7 deletions src/backend/common/jit/NaryNode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,17 @@ class NaryNode : public Node {
swap(m_op_str, other.m_op_str);
}

void genKerName(std::stringstream &kerStream,
void genKerName(std::string &kerString,
const common::Node_ids &ids) const final {
// Make the dec representation of enum part of the Kernel name
kerStream << "_" << std::setw(3) << std::setfill('0') << std::dec
<< m_op;
kerString += '_';
kerString += std::to_string(m_op);
kerString += ',';
for (int i = 0; i < m_num_children; i++) {
kerStream << std::setw(3) << std::setfill('0') << std::dec
<< ids.child_ids[i];
kerString += std::to_string(ids.child_ids[i]);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The zeros here are necessary to avoid naming conflicts.

kerString += ',';
}
kerStream << std::setw(3) << std::setfill('0') << std::dec << ids.id
<< std::dec;
kerString += std::to_string(ids.id);
}

void genFuncs(std::stringstream &kerStream,
Expand Down
18 changes: 6 additions & 12 deletions src/backend/common/jit/Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +41,20 @@ int Node::getNodesMap(Node_map_t &node_map, vector<Node *> &full_nodes,
std::string getFuncName(const vector<Node *> &output_nodes,
const vector<Node *> &full_nodes,
const vector<Node_ids> &full_ids, bool is_linear) {
std::stringstream funcName;
std::stringstream hashName;

if (is_linear) {
funcName << "L_"; // Kernel Linear
} else {
funcName << "G_"; // Kernel General
}
std::string funcName;
funcName.reserve(512);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am guessing this is the primary reason for the performance increase. I don't think its possible to do something similar with string stream.

funcName = (is_linear ? 'L' : 'G');

for (const auto &node : output_nodes) {
funcName << node->getNameStr() << "_";
funcName += '_';
funcName += node->getNameStr();
}

for (int i = 0; i < static_cast<int>(full_nodes.size()); i++) {
full_nodes[i]->genKerName(funcName, full_ids[i]);
}

hashName << "KER";
hashName << deterministicHash(funcName.str());
return hashName.str();
return "KER" + std::to_string(deterministicHash(funcName));
}

} // namespace common
2 changes: 1 addition & 1 deletion src/backend/common/jit/Node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class Node {
std::vector<Node_ids> &full_ids);

/// Generates the string that will be used to hash the kernel
virtual void genKerName(std::stringstream &kerStream,
virtual void genKerName(std::string &kerString,
const Node_ids &ids) const = 0;

/// Generates the function parameters for the node.
Expand Down
9 changes: 5 additions & 4 deletions src/backend/common/jit/ScalarNode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,12 @@ class ScalarNode : public common::Node {
swap(m_val, other.m_val);
}

void genKerName(std::stringstream& kerStream,
void genKerName(std::string& kerString,
const common::Node_ids& ids) const final {
kerStream << "_" << getTypeStr();
kerStream << std::setw(3) << std::setfill('0') << std::dec << ids.id
<< std::dec;
kerString += '_';
kerString += getTypeStr();
kerString += ',';
kerString += std::to_string(ids.id);
}

void genParams(std::stringstream& kerStream, int id,
Expand Down
9 changes: 5 additions & 4 deletions src/backend/common/jit/ShiftNodeBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,12 @@ class ShiftNodeBase : public Node {
return false;
}

void genKerName(std::stringstream &kerStream,
void genKerName(std::string &kerString,
const common::Node_ids &ids) const final {
kerStream << "_" << getNameStr();
kerStream << std::setw(3) << std::setfill('0') << std::dec << ids.id
<< std::dec;
kerString += '_';
kerString += getNameStr();
kerString += ',';
kerString += std::to_string(ids.id);
}

void genParams(std::stringstream &kerStream, int id,
Expand Down
4 changes: 2 additions & 2 deletions src/backend/cpu/jit/BinaryNode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ class BinaryNode : public TNode<compute_t<To>> {
m_op.eval(this->m_val, m_lhs->m_val, m_rhs->m_val, lim);
}

void genKerName(std::stringstream &kerStream,
void genKerName(std::string &kerString,
const common::Node_ids &ids) const final {
UNUSED(kerStream);
UNUSED(kerString);
UNUSED(ids);
}

Expand Down
4 changes: 2 additions & 2 deletions src/backend/cpu/jit/BufferNode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ class BufferNode : public TNode<T> {

size_t getBytes() const final { return m_bytes; }

void genKerName(std::stringstream &kerStream,
void genKerName(std::string &kerString,
const common::Node_ids &ids) const final {
UNUSED(kerStream);
UNUSED(kerString);
UNUSED(ids);
}

Expand Down
4 changes: 2 additions & 2 deletions src/backend/cpu/jit/ScalarNode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ class ScalarNode : public TNode<T> {
public:
ScalarNode(T val) : TNode<T>(val, 0, {}) {}

void genKerName(std::stringstream &kerStream,
void genKerName(std::string &kerString,
const common::Node_ids &ids) const final {
UNUSED(kerStream);
UNUSED(kerString);
UNUSED(ids);
}

Expand Down
4 changes: 2 additions & 2 deletions src/backend/cpu/jit/UnaryNode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ class UnaryNode : public TNode<To> {
m_op.eval(TNode<To>::m_val, m_child->m_val, lim);
}

void genKerName(std::stringstream &kerStream,
void genKerName(std::string &kerString,
const common::Node_ids &ids) const final {
UNUSED(kerStream);
UNUSED(kerString);
UNUSED(ids);
}

Expand Down