Repository: pytorch/torchdynamo

Issue:
pyhpc_equation_of_state failed after https://github.com/pytorch/torchdynamo/pull/337
Command to run, `./torchbench.py --inductor -dcuda -k pyhpc_equation_of_state`

Triaged down to this RP, https://github.com/pytorch/torchdynamo/pull/337

The problem seems related to half-precision because the test runs ok if adding `--float32`.

```
cuda eval  pyhpc_equation_of_state            Call parameter type does not match function signature!
  %553 = fadd double 1.000000e+00, %545
 float  %577 = call float asm "lg2.approx.f32 $0, $1;", "=f,f"(double %553)
Call parameter type does not match function signature!
  %554 = fadd double 1.000000e+00, %546
 float  %579 = call float asm "lg2.approx.f32 $0, $1;", "=f,f"(double %554)
Call parameter type does not match function signature!
  %555 = fadd double 1.000000e+00, %547
 float  %581 = call float asm "lg2.approx.f32 $0, $1;", "=f,f"(double %555)
Call parameter type does not match function signature!
  %556 = fadd double 1.000000e+00, %548
 float  %583 = call float asm "lg2.approx.f32 $0, $1;", "=f,f"(double %556)
Call parameter type does not match function signature!
  %557 = fadd double 1.000000e+00, %549
 float  %585 = call float asm "lg2.approx.f32 $0, $1;", "=f,f"(double %557)
Call parameter type does not match function signature!
  %558 = fadd double 1.000000e+00, %550
 float  %587 = call float asm "lg2.approx.f32 $0, $1;", "=f,f"(double %558)
Call parameter type does not match function signature!
  %559 = fadd double 1.000000e+00, %551
 float  %589 = call float asm "lg2.approx.f32 $0, $1;", "=f,f"(double %559)
Call parameter type does not match function signature!
  %560 = fadd double 1.000000e+00, %552
 float  %591 = call float asm "lg2.approx.f32 $0, $1;", "=f,f"(double %560)
Both operands to a binary operator are not of the same type!
  %593 = fmul double %569, float %578
Both operands to a binary operator are not of the same type!
  %594 = fmul double %570, float %580
Both operands to a binary operator are not of the same type!
  %595 = fmul double %571, float %582
Both operands to a binary operator are not of the same type!
  %596 = fmul double %572, float %584
Both operands to a binary operator are not of the same type!
  %597 = fmul double %573, float %586
Both operands to a binary operator are not of the same type!
  %598 = fmul double %574, float %588
Both operands to a binary operator are not of the same type!
  %599 = fmul double %575, float %590
Both operands to a binary operator are not of the same type!
  %600 = fmul double %576, float %592
in function kernel2__Pfp64_Pfp64_Pfp64_Pfp64_Pfp64_Pfp64_Pfp64_Pfp64_Pfp64_Pfp64_Pfp64_Pfp64_Pfp64__13c1082016_14c1024
LLVM ERROR: Broken function found, compilation aborted!
```


Discussion:
Thanks, I'll take a look.  I'm not seeing this in my branch, so I may need to cherry pick a fix to main.
Root cause of this is https://github.com/openai/triton/issues/543

I'll submit a workaround.

Resolving patch:
diff --git a/torchbench.py b/torchbench.py
--- a/torchbench.py
+++ b/torchbench.py
@@ -1018,6 +1018,9 @@ def main():
         if args.float16:
             # TODO(jansel): check if correctness issue is real
             SKIP.add("yolov3")
+        if not (args.float16 or args.float32):
+            # https://github.com/openai/triton/issues/543 causes only 98.8% similarity
+            NONDETERMINISTIC.add("pyhpc_equation_of_state")
 
     if args.float16:
         # these give `INCORRECT - Variation in Eager runs itself` sometimes
diff --git a/torchinductor/codegen/triton.py b/torchinductor/codegen/triton.py
--- a/torchinductor/codegen/triton.py
+++ b/torchinductor/codegen/triton.py
@@ -74,7 +74,8 @@ def sqrt(x):
 
     @staticmethod
     def log(x):
-        return f"tl.log({x})"
+        # workaround https://github.com/openai/triton/issues/543
+        return f"tl.log({x}.to(tl.float32))"
 
     @staticmethod
     def isinf(x):


Test patch: