Skip to content

[BUG] Identity comparison ('is') on JSON data strings in examples/44 multi-gemm codegen #3910

Open

Description

@3453-315h

Which component has the problem?

CUTLASS C++

Bug Report

Describe the bug
In examples/44_multi_gemm_ir_and_codegen, configuration data structures are parsed from JSON inputs via json.load(infile). The codegen scripts then perform is identity comparisons against string literals to check formatting/types (e.g. self.fuse_gemm_info[i]['B_format'] is 'Row').

Under Python (CPython 3.8+), using is with string literals produces a SyntaxWarning: "is" with a literal. Did you mean "=="?. More critically, strings decoded by json.load / json.loads are dynamically allocated and fail identity comparison with interned string literals, causing layout branches to never be entered.

Steps/Code to reproduce bug

import json
d = json.loads('{"B_format": "Row"}')
print(d['B_format'] is 'Row')  # Evaluates to False, emitting SyntaxWarning
print(d['B_format'] == 'Row')  # Evaluates to True

Affected locations:

  • examples/44_multi_gemm_ir_and_codegen/ir_gen/gen_turing_and_volta.py:84, 295, 297, 299
  • examples/44_multi_gemm_ir_and_codegen/ir_gen/gen_sample.py:185, 187, 189
  • examples/44_multi_gemm_ir_and_codegen/ir_gen/gen_device.py:85, 88

Expected behavior
Strings parsed from JSON should be compared for equality using ==.

Environment details:

  • Tested on Python 3.10 / 3.12, current main (HEAD: dc6ae46)

Proposed Solution
Replace is with == across examples/44_multi_gemm_ir_and_codegen/ir_gen/:

--- a/examples/44_multi_gemm_ir_and_codegen/ir_gen/gen_turing_and_volta.py
+++ b/examples/44_multi_gemm_ir_and_codegen/ir_gen/gen_turing_and_volta.py
@@ -81,3 +81,3 @@ class GeneratorTuringAndVolta(Generator):
         for i in range(len(self.fuse_gemm_info)):
-            if self.fuse_gemm_info[i]['B_format'] is 'Row':
+            if self.fuse_gemm_info[i]['B_format'] == 'Row':

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions