Skip to content

catalyst.print incorrectly stacks multiple literals #1747

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

Open
paul0403 opened this issue May 16, 2025 · 7 comments
Open

catalyst.print incorrectly stacks multiple literals #1747

paul0403 opened this issue May 16, 2025 · 7 comments
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@paul0403
Copy link
Member

paul0403 commented May 16, 2025

Since debug.print in frontend traces to callbacks instead of print_p now, I am using replace_ir to showcase this bug.

import catalyst
from catalyst import qjit, debug

@qjit(keep_intermediate=False)
def foo():
	return
foo()

new_ir = """
module @foo {
  func.func public @jit_foo() attributes {llvm.emit_c_interface} {
  	"catalyst.print"() {const_val = "Hello, Catalyst"} : () -> ()
  	"catalyst.print"() {const_val = "Hello again, Catalyst"} : () -> ()
    return
  }
  func.func @setup() {
    quantum.init
    return
  }
  func.func @teardown() {
    quantum.finalize
    return
  }
}
"""

debug.replace_ir(foo, "mlir", new_ir)
foo()
Hello, Catalyst@
Hello again, CatalystHello, Catalyst@
@paul0403 paul0403 added bug Something isn't working good first issue Good for newcomers labels May 16, 2025
@erick-xanadu
Copy link
Contributor

@paul0403 , is this stacking or just that the strings are not null terminated?

@paul0403
Copy link
Member Author

The strings are not null terminated in the runtime stub.

@erick-xanadu
Copy link
Contributor

It is kind of weird. We had this error in the past, but it was fixed... #404

@paul0403
Copy link
Member Author

Just a note that the frontend pytest does not see this because

Since debug.print in frontend traces to callbacks instead of print_p now, I am using replace_ir to showcase this bug.

@paul0403
Copy link
Member Author

Ahh, then the null terminator in in print primitive lowering (added in the fix #418) was not added!

@erick-xanadu
Copy link
Contributor

erick-xanadu commented May 16, 2025

Is it possible to print strings using the print_p primitive now from the frontend? Or is it only used for memrefs? Because if it is not reachable from the frontend, I would say that the error is in your program. Your strings are not null terminated.

@paul0403
Copy link
Member Author

I think you are right, print_p without memrefs and only pure string literals is unreachable in the frontend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants