Skip to content

Commit

Permalink
Merge with upstream (#202)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhil authored Jun 28, 2024
2 parents 8dcb8fc + 8cf6009 commit 83757e5
Show file tree
Hide file tree
Showing 167 changed files with 5,978 additions and 2,768 deletions.
50 changes: 20 additions & 30 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion ci/vendor-wit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,9 @@ cp -r $dst crates/wasi-http/wit
# slightly different than above.
repo=https://raw.githubusercontent.com/WebAssembly/wasi-nn
revision=e2310b
curl -L $repo/$revision/wit/wasi-nn.wit -o crates/wasi-nn/wit/wasi-nn.wit
curl -L $repo/$revision/wasi-nn.witx -o crates/wasi-nn/witx/wasi-nn.witx
# TODO: the in-tree `wasi-nn` implementation does not yet fully support the
# latest WIT specification on `main`. To create a baseline for moving forward,
# the in-tree WIT incorporates some but not all of the upstream changes. This
# TODO can be removed once the implementation catches up with the spec.
# curl -L $repo/$revision/wit/wasi-nn.wit -o crates/wasi-nn/wit/wasi-nn.wit
30 changes: 23 additions & 7 deletions cranelift/codegen/meta/src/cdsl/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,12 @@ impl LaneType {
/// Return a string containing the documentation comment for this lane type.
pub fn doc(self) -> String {
match self {
LaneType::Float(shared_types::Float::F16) => String::from(
"A 16-bit floating point type represented in the IEEE 754-2008
*binary16* interchange format. This corresponds to the :c:type:`_Float16`
type in most C implementations.
WARNING: f16 support is a work-in-progress and is incomplete",
),
LaneType::Float(shared_types::Float::F32) => String::from(
"A 32-bit floating point type represented in the IEEE 754-2008
*binary32* interchange format. This corresponds to the :c:type:`float`
Expand All @@ -146,6 +152,12 @@ impl LaneType {
*binary64* interchange format. This corresponds to the :c:type:`double`
type in most C implementations.",
),
LaneType::Float(shared_types::Float::F128) => String::from(
"A 128-bit floating point type represented in the IEEE 754-2008
*binary128* interchange format. This corresponds to the :c:type:`_Float128`
type in most C implementations.
WARNING: f128 support is a work-in-progress and is incomplete",
),
LaneType::Int(_) if self.lane_bits() < 32 => format!(
"An integer type with {} bits.
WARNING: arithmetic on {}bit integers is incomplete",
Expand All @@ -168,13 +180,15 @@ impl LaneType {
pub fn number(self) -> u16 {
constants::LANE_BASE
+ match self {
LaneType::Int(shared_types::Int::I8) => 6,
LaneType::Int(shared_types::Int::I16) => 7,
LaneType::Int(shared_types::Int::I32) => 8,
LaneType::Int(shared_types::Int::I64) => 9,
LaneType::Int(shared_types::Int::I128) => 10,
LaneType::Float(shared_types::Float::F32) => 11,
LaneType::Float(shared_types::Float::F64) => 12,
LaneType::Int(shared_types::Int::I8) => 4,
LaneType::Int(shared_types::Int::I16) => 5,
LaneType::Int(shared_types::Int::I32) => 6,
LaneType::Int(shared_types::Int::I64) => 7,
LaneType::Int(shared_types::Int::I128) => 8,
LaneType::Float(shared_types::Float::F16) => 9,
LaneType::Float(shared_types::Float::F32) => 10,
LaneType::Float(shared_types::Float::F64) => 11,
LaneType::Float(shared_types::Float::F128) => 12,
}
}

Expand All @@ -191,8 +205,10 @@ impl LaneType {

pub fn float_from_bits(num_bits: u16) -> LaneType {
LaneType::Float(match num_bits {
16 => shared_types::Float::F16,
32 => shared_types::Float::F32,
64 => shared_types::Float::F64,
128 => shared_types::Float::F128,
_ => unreachable!("unexpected num bits for float"),
})
}
Expand Down
32 changes: 16 additions & 16 deletions cranelift/codegen/meta/src/cdsl/typevar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::cdsl::types::{LaneType, ReferenceType, ValueType};

const MAX_LANES: u16 = 256;
const MAX_BITS: u16 = 128;
const MAX_FLOAT_BITS: u16 = 64;
const MAX_FLOAT_BITS: u16 = 128;

/// Type variables can be used in place of concrete types when defining
/// instructions. This makes the instructions *polymorphic*.
Expand Down Expand Up @@ -159,7 +159,7 @@ impl TypeVar {
"can't halve all integer types"
);
assert!(
ts.floats.is_empty() || *ts.floats.iter().min().unwrap() > 32,
ts.floats.is_empty() || *ts.floats.iter().min().unwrap() > 16,
"can't halve all float types"
);
}
Expand All @@ -179,7 +179,7 @@ impl TypeVar {
"can't halve all integer types"
);
assert!(
ts.floats.is_empty() || *ts.floats.iter().min().unwrap() > 32,
ts.floats.is_empty() || *ts.floats.iter().min().unwrap() > 16,
"can't halve all float types"
);
assert!(
Expand Down Expand Up @@ -464,7 +464,7 @@ impl TypeSet {
fn half_width(&self) -> TypeSet {
let mut copy = self.clone();
copy.ints = NumSet::from_iter(self.ints.iter().filter(|&&x| x > 8).map(|&x| x / 2));
copy.floats = NumSet::from_iter(self.floats.iter().filter(|&&x| x > 32).map(|&x| x / 2));
copy.floats = NumSet::from_iter(self.floats.iter().filter(|&&x| x > 16).map(|&x| x / 2));
copy
}

Expand Down Expand Up @@ -643,7 +643,7 @@ impl TypeSetBuilder {
range_to_set(self.simd_lanes.to_range(min_lanes..MAX_LANES, Some(1))),
range_to_set(self.dynamic_simd_lanes.to_range(2..MAX_LANES, None)),
range_to_set(self.ints.to_range(8..MAX_BITS, None)),
range_to_set(self.floats.to_range(32..64, None)),
range_to_set(self.floats.to_range(16..MAX_FLOAT_BITS, None)),
range_to_set(self.refs.to_range(32..64, None)),
)
}
Expand Down Expand Up @@ -711,7 +711,7 @@ fn test_typevar_builder() {

let type_set = TypeSetBuilder::new().floats(Interval::All).build();
assert_eq!(type_set.lanes, num_set![1]);
assert_eq!(type_set.floats, num_set![32, 64]);
assert_eq!(type_set.floats, num_set![16, 32, 64, 128]);
assert!(type_set.ints.is_empty());

let type_set = TypeSetBuilder::new()
Expand All @@ -720,7 +720,7 @@ fn test_typevar_builder() {
.includes_scalars(false)
.build();
assert_eq!(type_set.lanes, num_set![2, 4, 8, 16, 32, 64, 128, 256]);
assert_eq!(type_set.floats, num_set![32, 64]);
assert_eq!(type_set.floats, num_set![16, 32, 64, 128]);
assert!(type_set.ints.is_empty());

let type_set = TypeSetBuilder::new()
Expand All @@ -729,7 +729,7 @@ fn test_typevar_builder() {
.includes_scalars(true)
.build();
assert_eq!(type_set.lanes, num_set![1, 2, 4, 8, 16, 32, 64, 128, 256]);
assert_eq!(type_set.floats, num_set![32, 64]);
assert_eq!(type_set.floats, num_set![16, 32, 64, 128]);
assert!(type_set.ints.is_empty());

let type_set = TypeSetBuilder::new()
Expand All @@ -738,7 +738,7 @@ fn test_typevar_builder() {
.includes_scalars(false)
.build();
assert_eq!(type_set.lanes, num_set![2, 4, 8, 16, 32, 64, 128, 256]);
assert_eq!(type_set.floats, num_set![32, 64]);
assert_eq!(type_set.floats, num_set![16, 32, 64, 128]);
assert!(type_set.dynamic_lanes.is_empty());
assert!(type_set.ints.is_empty());

Expand All @@ -753,7 +753,7 @@ fn test_typevar_builder() {
num_set![2, 4, 8, 16, 32, 64, 128, 256]
);
assert_eq!(type_set.ints, num_set![8, 16, 32, 64, 128]);
assert_eq!(type_set.floats, num_set![32, 64]);
assert_eq!(type_set.floats, num_set![16, 32, 64, 128]);
assert_eq!(type_set.lanes, num_set![1]);

let type_set = TypeSetBuilder::new()
Expand All @@ -765,7 +765,7 @@ fn test_typevar_builder() {
type_set.dynamic_lanes,
num_set![2, 4, 8, 16, 32, 64, 128, 256]
);
assert_eq!(type_set.floats, num_set![32, 64]);
assert_eq!(type_set.floats, num_set![16, 32, 64, 128]);
assert_eq!(type_set.lanes, num_set![1]);
assert!(type_set.ints.is_empty());

Expand Down Expand Up @@ -871,12 +871,12 @@ fn test_forward_images() {
TypeSetBuilder::new().ints(8..16).build()
);
assert_eq!(
TypeSetBuilder::new().floats(32..32).build().half_width(),
TypeSetBuilder::new().floats(16..16).build().half_width(),
empty_set
);
assert_eq!(
TypeSetBuilder::new().floats(32..64).build().half_width(),
TypeSetBuilder::new().floats(32..32).build()
TypeSetBuilder::new().floats(32..128).build().half_width(),
TypeSetBuilder::new().floats(16..64).build()
);

// Double width.
Expand All @@ -893,8 +893,8 @@ fn test_forward_images() {
TypeSetBuilder::new().floats(64..64).build()
);
assert_eq!(
TypeSetBuilder::new().floats(32..64).build().double_width(),
TypeSetBuilder::new().floats(64..64).build()
TypeSetBuilder::new().floats(16..64).build().double_width(),
TypeSetBuilder::new().floats(32..128).build()
);
}

Expand Down
10 changes: 8 additions & 2 deletions cranelift/codegen/meta/src/shared/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ impl Iterator for IntIterator {

#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
pub(crate) enum Float {
F16 = 16,
F32 = 32,
F64 = 64,
F128 = 128,
}

/// Iterator through the variants of the Float enum.
Expand All @@ -63,8 +65,10 @@ impl Iterator for FloatIterator {
type Item = Float;
fn next(&mut self) -> Option<Self::Item> {
let res = match self.index {
0 => Some(Float::F32),
1 => Some(Float::F64),
0 => Some(Float::F16),
1 => Some(Float::F32),
2 => Some(Float::F64),
3 => Some(Float::F128),
_ => return None,
};
self.index += 1;
Expand Down Expand Up @@ -122,8 +126,10 @@ mod iter_tests {
#[test]
fn float_iter_works() {
let mut float_iter = FloatIterator::new();
assert_eq!(float_iter.next(), Some(Float::F16));
assert_eq!(float_iter.next(), Some(Float::F32));
assert_eq!(float_iter.next(), Some(Float::F64));
assert_eq!(float_iter.next(), Some(Float::F128));
assert_eq!(float_iter.next(), None);
}

Expand Down
Loading

0 comments on commit 83757e5

Please sign in to comment.