-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow larger output sizes for Concat
UNet caused errors because the Concat operator could not handle the large output sizes of some Concat operations. The solution for this is to change the workgroup dimensions to also use the y dimension. Since there is a limit of threads per dimension, this allows us quadratically increase the maximum possible output size.
- Loading branch information
Showing
3 changed files
with
96 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
use std::{collections::HashMap, convert::TryInto}; | ||
use wonnx::utils::{graph, model, node, tensor}; | ||
mod common; | ||
|
||
#[test] | ||
fn test_concat() { | ||
let n: usize = 16; | ||
|
||
let xdata: Vec<f32> = (0..n).map(|x| x as f32).collect(); | ||
let mut ydata: Vec<f32> = (n..2 * n).map(|x| x as f32).collect(); | ||
let input_dims = vec![n as i64]; | ||
let output_dims = vec![(n * 2) as i64]; | ||
|
||
let input_data = HashMap::from([ | ||
("X".into(), xdata.as_slice().into()), | ||
("Y".into(), ydata.as_slice().into()), | ||
]); | ||
|
||
let model = model(graph( | ||
vec![tensor("X", &input_dims), tensor("Y", &input_dims)], | ||
vec![tensor("Z", &output_dims)], | ||
vec![], | ||
vec![], | ||
vec![node(vec!["X", "Y"], vec!["Z"], "a", "Concat", vec![])], | ||
)); | ||
|
||
let session = | ||
pollster::block_on(wonnx::Session::from_model(model)).expect("Session did not create"); | ||
|
||
let result = pollster::block_on(session.run(&input_data)).unwrap(); | ||
|
||
let mut expected_result = xdata.clone(); | ||
expected_result.append(&mut ydata); | ||
|
||
common::assert_eq_vector((&result["Z"]).try_into().unwrap(), &expected_result); | ||
} | ||
|
||
#[test] | ||
fn test_concat4() { | ||
let n: usize = 13; | ||
|
||
let xdata: Vec<f32> = (0..n).map(|x| x as f32).collect(); | ||
let mut ydata: Vec<f32> = (n..2 * n).map(|x| x as f32).collect(); | ||
let mut zdata: Vec<f32> = (n * 2..3 * n).map(|x| x as f32).collect(); | ||
let mut wdata: Vec<f32> = (n * 3..4 * n).map(|x| x as f32).collect(); | ||
let input_dims = vec![n as i64]; | ||
let output_dims = vec![(n * 4) as i64]; | ||
|
||
let input_data = HashMap::from([ | ||
("X".into(), xdata.as_slice().into()), | ||
("Y".into(), ydata.as_slice().into()), | ||
("Z".into(), zdata.as_slice().into()), | ||
("W".into(), wdata.as_slice().into()), | ||
]); | ||
|
||
let model = model(graph( | ||
vec![ | ||
tensor("X", &input_dims), | ||
tensor("Y", &input_dims), | ||
tensor("Z", &input_dims), | ||
tensor("W", &input_dims), | ||
], | ||
vec![tensor("O", &output_dims)], | ||
vec![], | ||
vec![], | ||
vec![node(vec!["X", "Y", "Z", "W"], vec!["O"], "a", "Concat", vec![])], | ||
)); | ||
|
||
let session = | ||
pollster::block_on(wonnx::Session::from_model(model)).expect("Session did not create"); | ||
|
||
let result = pollster::block_on(session.run(&input_data)).unwrap(); | ||
|
||
let mut expected_result = xdata.clone(); | ||
expected_result.append(&mut ydata); | ||
expected_result.append(&mut zdata); | ||
expected_result.append(&mut wdata); | ||
|
||
common::assert_eq_vector((&result["O"]).try_into().unwrap(), &expected_result); | ||
} |