I worked on a boids simulation with mojo. Starting with a Lambda labs A10 GPU N^2 then a spatial hash version. Created kernels for spatial hash, histogram, scan, reorder and neighbor search. Text visualization for the different versions.
I think the core logic is ok but need more testing for sure. The spatial hash and scan working together were tricky for me. I think the scan algorithm needs more review but think everything is working.
More details in the repo’s readme
I didn’t finish a custom op integration but started that with the n^2 GPU version.
This is the error I get on my custom op
Traceback (most recent call last):
File “/home/ubuntu/mojo_swarm/boids.py”, line 118, in
result_from_mojo = run_boids_graph(
^^^^^^^^^^^^^^^^
File “/home/ubuntu/mojo_swarm/boids.py”, line 41, in run_boids_graph
agents_out = ops.custom(
^^^^^^^^^^^
File “/home/ubuntu/mojo_swarm/.pixi/envs/default/lib/python3.12/site-packages/max/graph/ops/custom.py”, line 98, in custom
graph._kernel_library.verify_custom_op(custom_op)
File “/home/ubuntu/mojo_swarm/.pixi/envs/default/lib/python3.12/site-packages/max/graph/graph.py”, line 141, in verify_custom_op
self._analysis.verify_custom_op(custom_op)
ValueError: Op ‘boids’ input at position 1 does not match registered kernel operand at position 2: Tensor[mut=False, fused=False] vs N: stdlib::Int. Detail: Mismatched types
I tried a bunch of things not sure seems like python passes an extra tensor, I probably don’t understand some subtle detail?