Henk-Jan Lebbink
MModular
•Created by Henk-Jan Lebbink on 2/29/2024 in #questions
How to tell Mojo that something is intended to be constant?
In mojo 24.1.0 (55ec12d6) I get a new warning:
'let' is being removed, please use 'var' insteadI think it is good practice to make explicity my intention that something is constant. How to I do that (in the future) since let is deprecated?
71 replies
MModular
•Created by Henk-Jan Lebbink on 2/10/2024 in #questions
Unnecessary nan-checks: performance issue or missing compile options.
I'm not sure whether this is a performance issue or a feature request. I figured lets ask here first.
The issue is a performance regression due to unnecessary nan-check for with (eg.) max and min operations.
+298 and +306 load data0 and data1 +314 calculates the maximum of zmm0 and zmm2 and store the result in zmm1 . +320 mask register k1 is set when zmm0 (data0) contains nan-values. +327 the result value (zmm1) is overwritten when the zmm0 was a nan with the value of data1 (zmm2) +333 result value is written back to memory If data0 could contain nan-values, the above assembly would be correct. But when data0 does not have such values, the code has a performance regression, because for every float min/max operations a nan-check is performed. This is something I would like to control in HPC AI workloads. Q: Is this a regression bug or something else (for which i need to make a feature request)?
+298 and +306 load data0 and data1 +314 calculates the maximum of zmm0 and zmm2 and store the result in zmm1 . +320 mask register k1 is set when zmm0 (data0) contains nan-values. +327 the result value (zmm1) is overwritten when the zmm0 was a nan with the value of data1 (zmm2) +333 result value is written back to memory If data0 could contain nan-values, the above assembly would be correct. But when data0 does not have such values, the code has a performance regression, because for every float min/max operations a nan-check is performed. This is something I would like to control in HPC AI workloads. Q: Is this a regression bug or something else (for which i need to make a feature request)?
6 replies
MModular
•Created by Henk-Jan Lebbink on 2/10/2024 in #questions
How to rewrite this code into something not ugly
I need to call
shuffle
on a parameter mask of different lengths, the following code is the shortest that I could make. Please fill in the dots to appreciate what would happen with width 1024. Any thoughts are appreciated.
10 replies
MModular
•Created by Henk-Jan Lebbink on 2/4/2024 in #questions
Prevent inline
Does anyone know a trick or official means to prevent a function from being inlined?
Any ugly trick would be fine.
9 replies
MModular
•Created by Henk-Jan Lebbink on 1/4/2024 in #questions
Counter-intuitive operator precedence
While debugging, I spotted a very counter-intuitive operator precedence evaluation.
Question: is it just me, or does the following code seem highly susceptible to bugs. If the code is indeed correct, does it serve as a nice example why we should be cautious about omitting parentheses? A warning would have saved me several hours of debugging...
4 replies
MModular
•Created by Henk-Jan Lebbink on 12/20/2023 in #questions
Does a pragma exist to switch off `mojo format`
I love the convention part of source code formatting rules: teams should not argue (too much) about formatting. Do this discussion once, agree on something that works for everyone (convention). Let the standard tooling handle it.
However, teams often agree that it needs to be switched off sometimes.
Question: Is there something to switch off sections of code that should not be formatted. A
@format on/off
would do.5 replies
MModular
•Created by Henk-Jan Lebbink on 12/17/2023 in #questions
How to cast SIMD when the size is known at compile time
In the following minimal code snippet
v
cannot be assigned to v2
. The error message is: cannot implicitly convert 'SIMD[si32, size]' value to 'SIMD[si32, 32]' in 'let' initializer
. But size is known to be equal to 32.
Question: how to convince the compiler that I'm a good citizen: trust me, this is ok, everyting will be fine...3 replies
MModular
•Created by Henk-Jan Lebbink on 12/17/2023 in #questions
Help with sort: it does not seem to do anything.
I'm a bit confused, I have a very simple sort example, but it does not do anything at all. I must be doing something wrong, because I cannot image that I'm the first to touch this code. What is going on here? The following code gives as output:
code:
5 replies
MModular
•Created by Henk-Jan Lebbink on 12/16/2023 in #questions
What to use for the permutation mask in SIMD.shuffle?
The following code snippet works; it is however not very convenient, especially when the SIMD width is a parameter.
Question: does someone know what I'm supposed to pass as mask in:
What other type could I use as
*mask
?2 replies
MModular
•Created by Henk-Jan Lebbink on 12/12/2023 in #questions
Compile Time Binary Tree in Mojo
I'm new to Mojo (who isn't), and I'm trying the language for something else than ML: metaprogramming. So I made a binary tree type that is generated at compile time. Here is a gist with 72 lines
Question: does such an approach make any sense? Am I pushing the language too far?
1 replies
MModular
•Created by Henk-Jan Lebbink on 12/8/2023 in #questions
What would be the target-triple to cross-compile for Graviton.
From the MAX Engine FAQ
Does MAX Engine support generic ARM architectures? Yes, both Mojo and MAX Engine support generic ARM architectures like Apple ARM chips. We formally benchmark ourselves on Graviton because it’s the most commonly used ARM chip for server deployments, and our benchmarks are designed to match what users use most often in production.What would be the target-triple to cross-compile my Mojo sources to ARM for AWS Graviton. I like to decompile the binaries and evaluate the quality of the assembly.
3 replies
MModular
•Created by Henk-Jan Lebbink on 12/5/2023 in #questions
Compilation does not terminate for recursive function
I'm porting some C++ with templates, and I realize that there is no such thing as
if constexpr
in mojo. Im trying to write something similar to the following test. However, compilation (not surprisingly) does not terminate.
Question: how do other people handle these straightforward recursive functions?
3 replies
MModular
•Created by Henk-Jan Lebbink on 11/7/2023 in #questions
How to implement the following simple comparison function
I would like to implement the following simple function, but I cannot find an alternative for AnyType (interface?) that defines comparison operators. In the following code a
__ne__
is needed for ai != bi
.
It's as if I'm missing a manual. If someone knows how to do this, or knows how to make me cope that is cannot be done...
3 replies
MModular
•Created by Henk-Jan Lebbink on 10/19/2023 in #questions
Non-trivial parameter are not matched
What is the expected behaviour while matching parameters. Should they be structurally equal, or is some rewriting on their AST expected? For example, the following code gives the error on the return of doubleCube.
because
1<<((N-1)+1)
is not considered equal to 1<<N
which suggests threre is no rewriting of parameters.
mojo 0.4.0 (9e33b013)
Question: is it reasonable that this non-trivial (but not ridiculous complex) parameter 1<<N
is matched? Or will this type of template programming be beyond the reach of Mojo?1 replies
MModular
•Created by Henk-Jan Lebbink on 10/19/2023 in #questions
Type system does not recognize that a literal int is equal to an Int alias
I have a simple struct called Cube:
I've simplified the code: what remains is the following issue. (Obviously, in this contrived example, N can just be replaced by 1), but for real-world code, I cannot.
Error:
cannot implicitly convert 'Cube[T, N]' value to 'Cube[T, 1]' in return value
mojo 0.4.0 (9e33b013)
Question: Does anyone know how to cast
my x
(of type Cube[T, N]
to Cube[T, 1]
? Or is there another way to get the type system to accept this?5 replies