← 返回首页
JIT optimization for sequential casts that are idempotent by jacobkahn · Pull Request #3031 · arrayfire/arrayfire · GitHub
Skip to content

Navigation Menu

Toggle navigation
Sign in
Appearance settings
Search or jump to...

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Include my email address so I can be contacted

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Resetting focus
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension .hpp  (1) All 1 file type selected Viewed files
Conversations
Failed to load comments. Retry
Loading
Jump to
Jump to file
Failed to load files. Retry
Loading
Diff view
Unified
Split
Hide whitespace
Apply and reload
Show whitespace
Diff view
Unified
Split
Hide whitespace
Apply and reload
Prev Previous commit
Next Next commit
cast: remove noop op, cast in node to UnaryNode
  • Loading branch information
jacobkahn authored and umar456 committed Mar 31, 2022
commit 70774a407493c2bf76792ff04d19cb7768a1ddd2
35 changes: 9 additions & 26 deletions src/backend/common/cast.hpp
Show comments View file Edit file Delete file Open in desktop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -41,32 +41,15 @@ struct CastWrapper {
// JIT optimization in the cast of multiple sequential casts that become
// idempotent - check to see if the previous operation was also a cast
// TODO: handle arbitrarily long chains of casts
auto in_node_nary =
std::dynamic_pointer_cast<common::NaryNode>(in_node);
if (in_node_nary && in_node_nary->getOp() == af_cast_t) {
// The only way to get the input type of the child node if it's a
// cast is to get the output type of the child's child.
auto in_node_children = in_node_nary->getChildren();
// Check if any children are casts with the same type - if so,
// insert a shortcut noop
for (size_t i = 0;
i < in_node_children.size() && in_node_nary->getChildren()[i];
++i) {
// Found a node whose child can be fast-track noop-ed
common::Node_ptr in_in_node = in_node_nary->getChildren()[i];
if (in_in_node->getType() == to_dtype) {
// If the output of the child's child is the same as the
// output of this node, ignore the input node and simply
// connect a noop node from the child's child to produce
// this op's output

// TODO: including unary.hpp to use
// detail::unaryName<af_noop_t> breaks some other stuff
return detail::createNodeArray<To>(
in.dims(),
common::Node_ptr(new common::UnaryNode(
to_dtype, "__noop", in_in_node, af_noop_t)));
}
auto in_node_unary =
std::dynamic_pointer_cast<common::UnaryNode>(in_node);
if (in_node_unary && in_node_unary->getOp() == af_cast_t) {
// child child's output type is the input type of the child
auto in_in_node = in_node_unary->getChildren()[0];
if (in_in_node->getType() == to_dtype) {
// ignore the input node and simply connect a noop node from the
// child's child to produce this op's output
return detail::createNodeArray<To>(in.dims(), in_in_node);
}
}

Expand Down
Toggle all file notes Toggle all file annotations

Footer

© 2026 GitHub, Inc.