Proposal: compile_function and enqueue_function need to become checked

I would like to see compile_function_checkedand enqueue_function_checkedbe marked as “deprecated” because compile_function and enqueue_function will implement the same functionality in some future version. (BUT, for the moment, please use the checked versions in the GPU programming tutorials for Mojo.)

Motivation: Mojo is a strongly typed language and the compiler detects almost all type mismatches. The GPU functions are an exception, where it is possible to pass the wrong argument type and screw up the results without any compiler warning.

My example is from a recent GPU exercise, where my results were screwed up because I had passed the literal 10.0 (Mojo Float64) as an argument where the GPU fn expected Float32. It took me a couple of hours to detect this, because it hadn’t occurred to me that a compiler that warns about a missing full stop in a docstring would let me make such a mistake.

This kind of argument mismatch is detected in Mojo CPU code. (It’s also detected in CUDA code.) Sure, if I was programming in Python or JavaScript I would check all my arguments; but my mindset is different when I’m programming in Mojo.

So, can you please add whatever behind the scenes code duplication or whatever is necessary so compile_function invokes the same checks as compile_function_checked and the same when enqueueing? I doubt that there is a noticeable performance loss from checking the arguments when enqueueing a GPU fnand it would make Mojo GPU programming simpler and less error-prone.

Sorry you hit the missing typechecking in the current enqueue_function, we know that’s been a sharp edge. We’re working hard to move to the future you describe, with enqueue_functionbeing replaced by what’s now called enqueue_function_checked.

However, there are some technical challenges with flipping every use of enqueue_function over to enqueue_function_checked. The first is that due to a compiler issue (that is being worked on), enqueue_function_checked currently takes the GPU function twice as a parameter. The second is that it requires all input types to be DevicePassable. Finally, its typechecking is exposing legitimate type issues with some GPU functions that had slipped through and need to be fixed.

We’re undertaking a migration of all of the MAX kernel code to use enqueue_function_checked, but due to the issues listed above this does require progressive replacement and some oversight when doing so. Once we have all of our own invocations of enqueue_function moved over, then we’ll explore changing the default over to the type-checked version. You may have to have a little patience with us while we thread this through, but in the meantime we do recommend trying to use enqueue_function_checked for your own GPU function code.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.