Kernel::ir; Rename Kernel::ir_holder to Kernel::ir.kernel to Blockkernel of the Kernel::irBlock::get_kernel: follow Block::parent to fetch the top-level block and return kernelStmt::get_kernel via its containing Blockvirtual Kernel *IRNode::get_kernel()get_current_program in irpassesX.get_kernel().program insteadCompileConfig arguments in passes like alg_simp(IRNode *root, const CompileConfig &config)Thank for purposing this. I also want to make compilerconfig contains stuffs like ti_enable_opengl, ti_gdb_teigger, and rename that to be a more generic name.
Get rid of the CompileConfig arguments in passes like alg_simp(IRNode *root, const CompileConfig &config
Can't we just make it global, or make alg_simp a class member func?
Thank for purposing this. I also want to make compilerconfig contains stuffs like ti_enable_opengl, ti_gdb_teigger, and rename that to be a more generic name.
Get rid of the CompileConfig arguments in passes like alg_simp(IRNode *root, const CompileConfig &config
Can't we just make it global, or make alg_simp a class member func?
I think it's better to get rid of the global get_current_program and the state variable Program::get_current_kernel so that we can support multiple programs and parallel kernel compilation.
A straightforward one can be make current_kernel a per-thread variable like errno. Or you move all functions with a get_current_program a member functiom of Program?
Change the type of
Kernel::irtostd::unique_ptr<Block>
Now I think this may be unnecessary, as all IR passes take as input IRNode * rather than Block *.
I suggest using std::unique_ptr<IRNode> while implementing more functions in IRNode like IRNode::clone, e.g., IRNode::get_kernel.
- [ ] Set
kernelof theKernel::ir
This point is a little ambiguous to me. If it means to set the Block::kernel member to kernel::ir, it then changes Block::kernel's type from Kernel* to IRNode*(and this breaks unique_ptr's idea). Could you please elaborate more on this? @yuanming-hu
Sorry about the ambiguity. Here I actually meant setting something like dynamic_cast<Block *>(kernel->ir.get())->kernel = kernel.
from
Kernel*toIRNode*
You mean from IRNode * to Block *? I'm not sure if I understand you correctly...
You mean _from
IRNode *toBlock *_? I'm not sure if I understand you correctly...
I assume that the added Block::kernel is of Kernel* and every get_kernel() return a Kernel*, so what I originally mean is that if setting Block::kernel to be the same type of Kernel::ir, it would change the type from Kernel* to something like IRNode*
Sorry about the ambiguity. Here I actually meant setting something like dynamic_cast
(kernel->ir.get())->kernel = kernel.
Thanks for the elaboration, then I am curious about when would this happen, maybe a rough hint?
I assume that the added
Block::kernelis ofKernel*and everyget_kernel()return aKernel*, so what I originally mean is that if settingBlock::kernelto be the same type ofKernel::ir, it would change the type fromKernel*to something likeIRNode*
I see. For now, we'd better not treat Kernel as an IRNode :-)
Thanks for the elaboration, then I am curious about when would this happen, maybe a rough hint?
Immediately after this line looks like a good place:
https://github.com/taichi-dev/taichi/blob/ae785ad4bc267c84396392da4a71167f082ab4c4/taichi/program/kernel.cpp#L46
Immediately after this line looks like a good place:
https://github.com/taichi-dev/taichi/blob/ae785ad4bc267c84396392da4a71167f082ab4c4/taichi/program/kernel.cpp#L46
Thanks! This is greatly helpful!
Actually we may utilize some helper functions in the codebase to simplify a bit:
dynamic_cast<Block *>(kernel->ir.get())->kernel = kernel
is equivalent with
kernel->ir->cast<Block>()->kernel = kernel
or (with assertion -- I prefer this one):
kernel->ir->as<Block>()->kernel = kernel
Most helpful comment
I see. For now, we'd better not treat
Kernelas anIRNode:-)Immediately after this line looks like a good place:
https://github.com/taichi-dev/taichi/blob/ae785ad4bc267c84396392da4a71167f082ab4c4/taichi/program/kernel.cpp#L46