mojo
安装方式
先用 Prompt 核对来源与依赖。也可下载安装包。
用 AI 助手安装
复制提示词,让助手先核对固定版本和依赖。
查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "mojo":https://skillpi.com/zh/skills/deepskill-3d01598f6a114160b1c947871569d300ef3009629c561544bde70d2f5ec2ed5a。安装前核对上游来源和版本:https://github.com/TerminalSkills/skills。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。
来源与配置
github.com
配置方式待核实
请查看原始来源中的适用工具、依赖和权限要求。
安装实测待补充
为 Mojo 编程语言提供专业指导,帮助开发者将 Python 代码逐步迁移到 Mojo,以获得接近 C 语言的性能。侧重高性能 AI/ML 代码编写,包括基于 SIMD 和并行化的数值计算优化与性能调优建议。
介绍来源: third_party · TerminalSkills · 1.0.0 参考来源
SkillPi 解读
- 能完成的任务
- 翻译待完成,请参阅来源文档。
- 实测状态
- 未测试
文件浏览
Frontmatter
name: mojo
description: Expert guidance for Mojo, the programming language by Modular that combines Python's usability with C-level performance. Helps developers write high-performance AI/ML code, optimize numerical computations with SIMD and parallelism, and gradually port Python code to Mojo for orders-of-magnitude speedups.
license: Apache-2.0
compatibility: No special requirements
metadata:
author: terminal-skills
version: 1.0.0
category: development
tags:
- mojo
- modular
- python
- performance
- aiMojo — Python-Speed Systems Language for AI
Overview
Mojo, the programming language by Modular that combines Python's usability with C-level performance. Helps developers write high-performance AI/ML code, optimize numerical computations with SIMD and parallelism, and gradually port Python code to Mojo for orders-of-magnitude speedups.
Instructions
Python Compatibility
# Mojo can run Python code directly and call Python libraries.
# Start with Python, optimize hot paths in Mojo.
from python import Python
fn main() raises:
# Import any Python library
let np = Python.import_module("numpy")
let plt = Python.import_module("matplotlib.pyplot")
# Use NumPy arrays as usual
let data = np.random.randn(1000)
let mean = np.mean(data)
let std = np.std(data)
print("Mean:", mean, "Std:", std)
# Plot with matplotlib
plt.hist(data, bins=30)
plt.title("Distribution")
plt.savefig("plot.png")
High-Performance Structs
# matrix.mojo — Custom matrix type with SIMD operations
# This runs 10-100x faster than equivalent NumPy for small matrices.
from math import sqrt
from algorithm import vectorize, parallelize
struct Matrix:
var data: DTypePointer[DType.float64]
var rows: Int
var cols: Int
fn __init__(inout self, rows: Int, cols: Int):
self.rows = rows
self.cols = cols
self.data = DTypePointer[DType.float64].alloc(rows * cols)
memset_zero(self.data, rows * cols)
fn __getitem__(self, row: Int, col: Int) -> Float64:
return self.data.load(row * self.cols + col)
fn __setitem__(inout self, row: Int, col: Int, val: Float64):
self.data.store(row * self.cols + col, val)
fn __del__(owned self):
self.data.free()
fn matmul(self, other: Matrix) -> Matrix:
"""Matrix multiplication using SIMD vectorization.
Processes multiple floating-point operations per CPU instruction.
On a modern CPU with 256-bit SIMD, this processes 4 float64 ops
at once — a 4x speedup over scalar code.
"""
var result = Matrix(self.rows, other.cols)
let simd_width = simdwidthof[DType.float64]()
@parameter
fn calc_row(row: Int):
for k in range(self.cols):
@parameter
fn dot[simd_width: Int](col: Int):
result.data.store[width=simd_width](
row * other.cols + col,
result.data.load[width=simd_width](row * other.cols + col)
+ self[row, k] * other.data.load[width=simd_width](k * other.cols + col)
)
vectorize[dot, simd_width](other.cols)
parallelize[calc_row](self.rows) # Parallelize across CPU cores
return result
fn frobenius_norm(self) -> Float64:
"""Compute the Frobenius norm using SIMD reduction."""
var sum: Float64 = 0.0
let simd_width = simdwidthof[DType.float64]()
@parameter
fn accumulate[width: Int](idx: Int):
let vals = self.data.load[width=width](idx)
sum += (vals * vals).reduce_add()
vectorize[accumulate, simd_width](self.rows * self.cols)
return sqrt(sum)
SIMD and Vectorization
# simd_example.mojo — Process data in parallel lanes
from algorithm import vectorize
from sys.info import simdwidthof
fn relu_activation(inout data: DTypePointer[DType.float32], size: Int):
"""Apply ReLU activation using SIMD.
Processes 8 float32 values simultaneously on AVX2 CPUs,
or 16 on AVX-512. The @parameter decorator ensures the
SIMD width is resolved at compile time.
"""
let simd_width = simdwidthof[DType.float32]() # 8 on AVX2
@parameter
fn apply_relu[width: Int](idx: Int):
let values = data.load[width=width](idx)
let zeros = SIMD[DType.float32, width](0)
data.store[width=width](idx, values.max(zeros))
vectorize[apply_relu, simd_width](size)
fn softmax(inout data: DTypePointer[DType.float32], size: Int):
"""Numerically stable softmax with SIMD operations."""
# Find max for numerical stability
var max_val: Float32 = data.load(0)
for i in range(1, size):
let val = data.load(i)
if val > max_val:
max_val = val
# Compute exp(x - max) and sum
var sum: Float32 = 0.0
for i in range(size):
let exp_val = math.exp(data.load(i) - max_val)
data.store(i, exp_val)
sum += exp_val
# Normalize
let inv_sum = 1.0 / sum
let simd_width = simdwidthof[DType.float32]()
@parameter
fn normalize[width: Int](idx: Int):
data.store[width=width](idx, data.load[width=width](idx) * inv_sum)
vectorize[normalize, simd_width](size)
Parallelism
# parallel.mojo — Multi-core parallel processing
from algorithm import parallelize, vectorize
from time import now
fn parallel_image_processing(
inout pixels: DTypePointer[DType.uint8],
width: Int,
height: Int,
):
"""Apply grayscale conversion in parallel across CPU cores.
Each row is processed by a different core, and within each row,
SIMD processes multiple pixels simultaneously.
"""
@parameter
fn process_row(row: Int):
let row_offset = row * width * 3 # 3 channels (RGB)
for col in range(width):
let idx = row_offset + col * 3
let r = pixels.load(idx).cast[DType.float32]()
let g = pixels.load(idx + 1).cast[DType.float32]()
let b = pixels.load(idx + 2).cast[DType.float32]()
# Luminance formula: 0.299R + 0.587G + 0.114B
let gray = (0.299 * r + 0.587 * g + 0.114 * b).cast[DType.uint8]()
pixels.store(idx, gray)
pixels.store(idx + 1, gray)
pixels.store(idx + 2, gray)
parallelize[process_row](height) # Each core handles a subset of rows
Installation
# Install Modular CLI
curl -s https://get.modular.com | sh -
# Install Mojo
modular install mojo
# Verify
mojo --version
# Run a Mojo file
mojo run my_program.mojo
# Build a binary
mojo build my_program.mojo -o my_program
Examples
Example 1: Building a feature with Mojo
User request:
Add a real-time collaborative python compatibility to my React app using Mojo.
The agent installs the package, creates the component with proper Mojo initialization, implements the python compatibility with event handling and state management, and adds TypeScript types for the integration.
Example 2: Migrating an existing feature to Mojo
User request:
I have a basic high-performance structs built with custom code. Migrate it to use Mojo for better high-performance structs support.
The agent reads the existing implementation, maps the custom logic to Mojo's API, rewrites the components using Mojo's primitives, preserves existing behavior, and adds features only possible with Mojo (like SIMD and Vectorization, Parallelism).
Guidelines
- Start with Python, optimize in Mojo — Use Python imports for prototyping; rewrite hot loops in native Mojo for 10-1000x speedups
- Use SIMD for data processing —
vectorizeprocesses multiple values per instruction; always prefer it over scalar loops for numeric data - Parallelize across cores —
parallelizedistributes work across CPU cores; combine withvectorizefor maximum throughput fnoverdef— Usefnfor performance-critical functions (strict typing, no overhead); usedeffor flexibility- Owned and borrowed references — Use
borrowed(default) for read-only,inoutfor mutation,ownedfor transfers; this enables zero-copy optimizations - Compile-time metaprogramming — Use
@parameterfor compile-time evaluation; SIMD widths, loop unrolling, and specialization happen at compile time - Profile before optimizing — Use
mojo build -O3and benchmark; not everything needs SIMD — focus on actual bottlenecks - Gradual migration — Port one function at a time from Python to Mojo; the interop layer makes incremental adoption easy
当前收录版本
1.0.0
质量评测
满分100 · 来自 SkillPi LAB 实验室的评测报告。
亮点
- 提供 Mojo 编程语言的专业指导,涵盖 Python 兼容性、高性能结构体、SIMD 向量化、多核并行化等核心特性
- 包含完整的代码示例和实际应用场景(AI/ML 数值计算优化、图像处理等),解决开发者性能关键场景的实际痛点
亮点
- 触发词精准完整,覆盖 Mojo 语言核心概念(Python 兼容性、C 级性能、SIMD、并行化、AI/ML 代码优化、Python 代码移植)
- description 位于顶层 frontmatter,内容完整清晰,边界明确不易混淆
亮点
- 结构清晰完整:Overview → Instructions → Installation → Examples → Guidelines
- 每个代码示例均有详细注释和性能说明,包含端到端示例(矩阵乘法、ReLU 激活、图像灰度转换)
- frontmatter 完整,单文件长度适中
亮点
- 工具来源明确(Modular 官方 CLI),安装命令正确
- 代码示例语法正确,参数使用合理,覆盖主要异常场景(raises 异常处理、数值稳定性处理)
- 内存管理等不可逆操作有对应机制
取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。
正文静态检测
100 / 100 · skillpi-20261123-no-r3-v1
正文未命中当前规则。
分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。
权限与使用前检查
根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。
未从主文档识别到上述常见操作,不能据此判断无需权限或没有风险。
文档引用的域名或地址
这些地址可能用于文档链接或示例,不是已批准的联网清单。使用前核对实际目的地及发送的数据。
- get.modular.com
安全评级与访问范围
safe · 静态证据核验,不代表运行安全保证。
使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。
用户讨论
还没有已核实的点评。