Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor counters to scoped-counters #4577

Closed
1 of 4 tasks
PGZXB opened this issue Mar 19, 2022 · 0 comments
Closed
1 of 4 tasks

Refactor counters to scoped-counters #4577

PGZXB opened this issue Mar 19, 2022 · 0 comments
Assignees
Labels
c++ C++ engineering related refactor Refactor of API or codebases

Comments

@PGZXB
Copy link
Contributor

PGZXB commented Mar 19, 2022

Following #4561, in C++ codebase of Taichi, many counters are used to identify a instance. But the counters are global now, which causes some problems. Using Taichi AST string generated by irpass::print as offline-cache-key (#4401) cannot identify a kernel completely because of global counters. We need scoped-counters.

An example in which I found problem

ti.init(arch=ti.cpu, print_preprocessed_ir=True)

@ti.kernel
def f1():
  for i in range(100):
    pass

@ti.kernel
def f2():
  for i in range(100):
    pass

1st: f1(); f2(), Ouput:

[I 03/19/22 10:47:49.763 17728] [kernel.cpp:lower@79] [f1_c56_0] Preprocessed IR:
kernel {
  $0 : for @tmp0 in range((cast_value<i32> 0), (cast_value<i32> 100)) block_dim=adaptive {
  }
}
[I 03/19/22 10:47:49.792 17728] [kernel.cpp:lower@79] [f2_c58_0] Preprocessed IR:
kernel {
  $0 : for @tmp2 in range((cast_value<i32> 0), (cast_value<i32> 100)) block_dim=adaptive {
  }
}

2nd: f2(); f1(), Output:

[I 03/19/22 10:49:09.890 17800] [kernel.cpp:lower@79] [f2_c58_0] Preprocessed IR:
kernel {
  $0 : for @tmp0 in range((cast_value<i32> 0), (cast_value<i32> 100)) block_dim=adaptive {
  }
}
[I 03/19/22 10:49:09.919 17800] [kernel.cpp:lower@79] [f1_c56_0] Preprocessed IR:
kernel {
  $0 : for @tmp2 in range((cast_value<i32> 0), (cast_value<i32> 100)) block_dim=adaptive {
  }
}

One kernel's ir/ast-string is related with calling order, because the id: Identifier which is member of IdExpression has auto incremental id: int (depending on static int variable id_counter). Global id_counter causes the problem.
I think we can remove this counters, and make them scoped.

Counters in C++ Side

(Simply using reg "static.*int.*counter" to search)

  • Identifier::id_counter, global scope and kernel/func scope
  • SNode::counter, program(global) scope
  • Stmt::instance_id_counter, kernel/func scope
  • TaskLaunchRecord::task_counter, maybe kernel/func scope
@PGZXB PGZXB self-assigned this Mar 19, 2022
@PGZXB PGZXB added refactor Refactor of API or codebases c++ C++ engineering related labels Mar 19, 2022
@victoriacity victoriacity added this to To Triage in Compiler Frontend & Middle-end via automation Mar 25, 2022
@strongoier strongoier moved this from To Triage to In progress in Compiler Frontend & Middle-end Mar 25, 2022
@PGZXB PGZXB closed this as completed Jul 4, 2022
Compiler Frontend & Middle-end automation moved this from In progress to Done Jul 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ C++ engineering related refactor Refactor of API or codebases
Development

No branches or pull requests

1 participant