from sys import has_apple_gpu_accelerator
print(has_apple_gpu_accelerator())
gives False on jupyter-lab on my Macbook AIr M4. Is there a way to get it to work in jupyter? Also, can I get syntax highlighting in jupyter for mojo code?
from sys import has_apple_gpu_accelerator
print(has_apple_gpu_accelerator())
gives False on jupyter-lab on my Macbook AIr M4. Is there a way to get it to work in jupyter? Also, can I get syntax highlighting in jupyter for mojo code?
The legacy Mojo kernel for Jupyter has some odd quirks, and doesn’t appear to correctly interact with the way that we build for Apple silicon GPUs. That kernel has been subtly broken for a little while, and in the meantime we’ve been encouraging people to instead use the standard Python Jupyter kernel and run Mojo code using the %%mojo magic command. On my MacBook, that gets has_apple_accelerator() to correctly return True.
Select the Python 3 kernel, set up the Mojo magic with
import mojo.notebook
and then run the command in the cell using:
%%mojo
from sys import has_apple_gpu_accelerator
def main():
print("Hello Mojo", has_apple_gpu_accelerator())
This unfortunately won’t get you syntax highlighting yet, that’s something that is being looked into.
Thanks for this. works perfectly fine ![]()
Additionally, I found something on the Jupyter forum to add the mojo magic to all the cells. Simply adding the following code to the first cell of the notebook works for me.
import mojo.notebook
def run_all_cell_with_magics(lines):
new_lines = []
new_lines.append("%%mojo") #this works
#new_lines.append("%%timeit \n") # this does not work
for line in lines:
new_lines.append(line)
return new_lines
ip = get_ipython()
ip.input_transformers_cleanup.append(run_all_cell_with_magics)