프로젝트
GitHub에서 보기
mlir-rs/melior
소개
Rust로 작성된 MLIR 바인딩
개발 도구측정된 스타 증가
- in 24h
- 0
- in 7 days
- +2
- in 15 days
- +4
- in 1 month
- 기록 수집 중
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
OriginalMelior
Melior is the MLIR bindings for Rust. It aims to provide a simple, safe, and complete API for MLIR.
This crate is a wrapper of the MLIR C API.
Examples
Building a function to add integers
use melior::{
Context,
dialect::{DialectRegistry, arith, func},
ir::{
attribute::{StringAttribute, TypeAttribute},
operation::OperationLike,
r#type::FunctionType,
*,
},
utility::register_all_dialects,
};
let registry = DialectRegistry::new();
register_all_dialects(®istry);
let context = Context::new();
context.append_dialect_registry(®istry);
context.load_all_available_dialects();
let location = Location::unknown(&context);
let module = Module::new(location);
let index_type = Type::index(&context);
module.body().append_operation(func::func(
&context,
StringAttribute::new(&context, "add"),
TypeAttribute::new(
FunctionType::new(&context, &[index_type, index_type], &[index_type]).into(),
),
{
let block = Block::new(&[index_type, index_type], &[location, location]).unwrap();
let sum = block
.append_operation(arith::addi(
block.argument(0).unwrap().into(),
block.argument(1).unwrap().into(),
location,
))
.result(0)
.unwrap();
block.append_operation(func::r#return(&[sum.into()], location));
let region = Region::new();
region.append_block(block);
region
},
&[],
location,
));
assert!(module.as_operation().verify());
Install
cargo add melior
Dependencies
LLVM/MLIR 23 needs to be installed on your system. On Linux and macOS, you can install it via Homebrew.
brew install llvm@23
Documentation
On GitHub Pages.
Contribution
Contribution is welcome! But, Melior is still in the alpha stage as well as the MLIR C API. Note that the API is unstable and can have breaking changes in the future.
Naming conventions
Mlir<X>objects are named<X>if they have no destructor. Otherwise, they are named<X>for owned objects and<X>Reffor borrowed references.mlir<X>Createfunctions are renamed as<X>::new.mlir<X>Get<Y>functions are renamed as follows:- If the resulting objects refer to
&self, they are named<X>::as_<Y>. - Otherwise, they are named just
<X>::<Y>and may have arguments, such as position indices.
- If the resulting objects refer to
Safety
Although Melior aims to be completely type safe, some part of the current API is not.
- Access to operations, types, or attributes that belong to dialects not
loaded in contexts can lead to runtime errors or segmentation faults in
the worst case.
- Fix plan: Load all dialects by default on creation of contexts, and provide unsafe constructors of contexts for advanced users.
- IR object references returned from functions that move ownership of
arguments might get invalidated later.
- This is because we need to borrow
&selfrather than&mut selfto return such references. - e.g.
Region::append_block() - Fix plan: Use dynamic check, such as
RefCell, for the objects.
- This is because we need to borrow
- Because of defects in the MLIR parser, parsing malformed IR text can read memory out of bounds or crash the process, and so can uses of the objects it creates. Untrusted text must not be parsed.
- e.g.
Attribute::parse()withdense<(1, 2)> : tensor<5xi32> - Fix plan: Fix the defects in the MLIR parser upstream.
- e.g.
References
- The raw C binding generation depends on mlir-rs/mlir-sys.
- The overall design is inspired by TheDan64/inkwell.
License
관련 프로젝트 살펴보기
불러오는 중…