[code-reflection] RFR: PTX backend implementation for HAT
Gary Frost
gfrost at openjdk.org
Tue Jul 23 08:47:45 UTC 2024
On Fri, 19 Jul 2024 19:36:16 GMT, Ruby Chen <duke at openjdk.org> wrote:
> Implemented a PTX backend for HAT kernel execution; PTX will run on machines with supporting Nvidia GPUs. Currently works for Squares and Mandel kernel examples.
>
> Also starting to implement a BlackScholes kernel for HAT.
At this time I focused on the PTXCodeBuilder.
Generally look at options other than calling append() directly, build more fine grained builder helpers.
hat/backends/ptx/src/main/java/hat/backend/PTXCodeBuilder.java line 90:
> 88:
> 89: public void ptxHeader(int major, int minor, String target, int addressSize) {
> 90: append(".version ").append(String.valueOf(major)).dot().append(String.valueOf(minor)).nl();
I see quite a few uses of append in this file.
Generally when using your own builder 'dialect' (in this case PTXBuilder), consider each use of raw append and determine whether you should add a specific build method.
Also don't include '.' and ' ' (space) in strings (as in append(".version ") prefer explicit dot() and space()
So maybe you add a specific version(), major(int) and minor(int) so your code would be
dot().version().space().major(major).dot().minor(minor).nl()
hat/backends/ptx/src/main/java/hat/backend/PTXCodeBuilder.java line 98:
> 96: public void functionHeader(String funcName, boolean entry, TypeElement yieldType) {
> 97: if (entry) {
> 98: append(".visible .entry ");
dot().visible().space().entry().space()?
hat/backends/ptx/src/main/java/hat/backend/PTXCodeBuilder.java line 105:
> 103: returnReg = new PTXRegister(getOrdinal(resultType(yieldType)), resultType(yieldType));
> 104: returnReg.name("%retReg");
> 105: oparen().param().space().printParamType(yieldType);
avoid prefixing with 'print' like this, everything going through the builder is essentially printing. Maybe just 'paramType(yieldType)'
hat/backends/ptx/src/main/java/hat/backend/PTXCodeBuilder.java line 263:
> 261: append("cvta.to").global().addrSize().space().printField(Field.KC_ADDR).commaSpace()
> 262: .printAndAddVar(paramMap.get("kc"), addrType()).ptxNl();
> 263: mov().u32().space().printField(Field.NTID_X).commaSpace().append("%ntid.x").ptxNl();
again 'printField ()' -> 'field()' , printAndAddVar() -> addVarAndType() .
consider 'cvta().dot().to()'
Rather than repeating these suggestions, look at all uses of printXXX and append and see it we can de
-------------
PR Review: https://git.openjdk.org/babylon/pull/188#pullrequestreview-2193337450
PR Review Comment: https://git.openjdk.org/babylon/pull/188#discussion_r1687658595
PR Review Comment: https://git.openjdk.org/babylon/pull/188#discussion_r1687661963
PR Review Comment: https://git.openjdk.org/babylon/pull/188#discussion_r1687661167
PR Review Comment: https://git.openjdk.org/babylon/pull/188#discussion_r1687669659
More information about the babylon-dev
mailing list