Skip to content

Commit 54e6686

Browse files
authored
Test snapshots (rustnn#166)
## Summary - [x] Describe the user-visible and code-level changes. - Remove bug trtx cuda_host_register - snapshot onnx and trtx test results ## Validation - [x] `make test` - [x] Relevant WPT or integration checks ## Documentation - [ ] Updated docs if behavior changed - [ ] If backend converter/executor operator support changed, ran `make docs-backend-ops` and committed `docs/development/backend-operator-support.md`
1 parent e7c3d3c commit 54e6686

4,955 files changed

Lines changed: 58760 additions & 113 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,4 @@ env/
5050
*.swo
5151
*~
5252
.DS_Store
53+
*.snap.new

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,9 @@ Contributions welcome! Please see:
192192
2. Install hooks (optional): `./scripts/install-git-hooks.sh`
193193
3. Make changes and test: `make test && make python-test`
194194
4. If Snapshots need to be updated (will be indicated by test failures),
195-
run `cargo insta review` (see https://insta.rs/docs/cli/ to install)
195+
run `cargo insta review` (see https://insta.rs/docs/cli/ to install) or
196+
`INSTA_UPDATE=always cargo test` to update all snapshots automatically
197+
(review before committing!)
196198
5. Format code: `make fmt`
197199
6. Commit and push
198200

src/backends/trtx.rs

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use std::borrow::Cow;
2-
use std::collections::{HashMap, HashSet};
2+
use std::collections::HashMap;
33
use std::ffi::c_void;
44
use std::mem::MaybeUninit;
55
use std::ops::Deref;
@@ -244,8 +244,6 @@ pub(crate) struct TrtxContext<'context> {
244244
cuda_ctx: Arc<CudaContext>,
245245
tensors: Vec<TrtxTensor>,
246246
events: Vec<CudaEvent>,
247-
attempted_host_registrations: HashSet<usize>,
248-
registered_host_pointers: HashMap<usize, usize>,
249247
runtime: Arc<Mutex<trtx::Runtime<'context>>>,
250248
config: Arc<Mutex<trtx::BuilderConfig<'context>>>, // needs to be destroyed before builder
251249
builder: Arc<Mutex<trtx::Builder<'context>>>,
@@ -283,34 +281,11 @@ impl<'context> TrtxContext<'context> {
283281
cuda_ctx,
284282
tensors: vec![],
285283
events: vec![],
286-
attempted_host_registrations: HashSet::new(),
287-
registered_host_pointers: HashMap::new(),
288284
runtime,
289285
builder: Arc::new(builder.into()),
290286
config,
291287
})
292288
}
293-
294-
fn try_register_host_memory(&mut self, pointer: *const u8, size: usize) {
295-
let pointer_address = pointer as usize;
296-
if !self.attempted_host_registrations.insert(pointer_address) {
297-
return;
298-
}
299-
300-
let registration_result = self.cuda_ctx.bind_to_thread().and_then(|()| unsafe {
301-
sys::cuMemHostRegister_v2(pointer.cast_mut().cast(), size, 0).result()
302-
});
303-
match registration_result {
304-
Ok(()) => {
305-
self.registered_host_pointers.insert(pointer_address, size);
306-
}
307-
Err(error) => {
308-
warn!(
309-
"Failed to register CPU tensor pointer {pointer:p} (size={size}) with CUDA: {error}"
310-
);
311-
}
312-
}
313-
}
314289
}
315290

316291
#[allow(dead_code)]
@@ -560,7 +535,6 @@ impl<'context> MLBackendContext<'context> for TrtxContext<'context> {
560535
tensor: &crate::mlcontext::MLTensor,
561536
array: &mut [u8],
562537
) -> crate::error::Result<()> {
563-
self.try_register_host_memory(array.as_ptr(), array.len());
564538
let cuda_tensor = &self.tensors[tensor.id];
565539
let stream = &cuda_tensor.stream;
566540
debug!(
@@ -582,7 +556,6 @@ impl<'context> MLBackendContext<'context> for TrtxContext<'context> {
582556
tensor: &crate::mlcontext::MLTensor,
583557
array: &[u8],
584558
) -> crate::error::Result<()> {
585-
self.try_register_host_memory(array.as_ptr(), array.len());
586559
let cuda_tensor = &mut self.tensors[tensor.id];
587560
let stream = &cuda_tensor.stream;
588561
debug!(

tests/run_wpt_conformance.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ use std::time::Instant;
44

55
use libtest_mimic::{Arguments, Completion, Failed, Trial};
66
use wpt_conformance::wpt_backend::WptBackend;
7-
use wpt_conformance::wpt_js_loader::{default_wpt_dir, load_wpt_corpus, trial_name};
7+
use wpt_conformance::wpt_js_loader::{
8+
default_wpt_dir, load_wpt_corpus, sanitize_test_id, trial_name,
9+
};
810
use wpt_conformance::wpt_report::{WptReportCollector, report_output_path};
911
use wpt_conformance::wpt_types::WptLoadedCase;
1012
use wpt_conformance::{run_one_test_case, should_skip_test, wpt_types::WptTestCase};
@@ -37,14 +39,20 @@ fn push_backend_trials(
3739
let file_name = case.file_name.clone();
3840
let test_name = case.name.clone();
3941
let backend_prefix = prefix.to_string();
42+
let snapshot_name = format!("{backend_prefix}_{}", sanitize_test_id(&test_name));
4043
let report = report.clone();
4144
let backend = backend.clone();
4245
trials.push(Trial::ignorable_test(name, move || {
4346
let started = Instant::now();
4447
let result = run_trial(&backend, &operation, &test_case);
4548
let duration = started.elapsed();
49+
4650
match &result {
4751
Ok(Completion::Completed) => {
52+
insta::assert_debug_snapshot!(
53+
snapshot_name,
54+
(&file_name, &test_name, &backend_prefix, "PASS")
55+
);
4856
report.record_pass(&file_name, &test_name, &backend_prefix, duration);
4957
}
5058
Ok(Completion::Ignored { reason }) => {
@@ -53,6 +61,10 @@ fn push_backend_trials(
5361
}
5462
Err(err) => {
5563
let msg = err.message().unwrap_or("test failed").to_string();
64+
insta::assert_snapshot!(
65+
snapshot_name,
66+
format!("{file_name} {test_name}, {backend_prefix}\n {msg}")
67+
);
5668
report.record_fail(&file_name, &test_name, &backend_prefix, msg, duration);
5769
}
5870
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
source: tests/run_wpt_conformance.rs
3+
expression: "(&file_name, &test_name, &backend_prefix, \"PASS\")"
4+
---
5+
(
6+
"abs.https.any.js",
7+
"abs float16 1D constant tensor",
8+
"onnx",
9+
"PASS",
10+
)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
source: tests/run_wpt_conformance.rs
3+
expression: "(&file_name, &test_name, &backend_prefix, \"PASS\")"
4+
---
5+
(
6+
"abs.https.any.js",
7+
"abs float16 1D tensor",
8+
"onnx",
9+
"PASS",
10+
)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
source: tests/run_wpt_conformance.rs
3+
expression: "(&file_name, &test_name, &backend_prefix, \"PASS\")"
4+
---
5+
(
6+
"abs.https.any.js",
7+
"abs float16 2D tensor",
8+
"onnx",
9+
"PASS",
10+
)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
source: tests/run_wpt_conformance.rs
3+
expression: "(&file_name, &test_name, &backend_prefix, \"PASS\")"
4+
---
5+
(
6+
"abs.https.any.js",
7+
"abs float16 3D tensor",
8+
"onnx",
9+
"PASS",
10+
)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
source: tests/run_wpt_conformance.rs
3+
expression: "(&file_name, &test_name, &backend_prefix, \"PASS\")"
4+
---
5+
(
6+
"abs.https.any.js",
7+
"abs float16 4D tensor",
8+
"onnx",
9+
"PASS",
10+
)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
source: tests/run_wpt_conformance.rs
3+
expression: "(&file_name, &test_name, &backend_prefix, \"PASS\")"
4+
---
5+
(
6+
"abs.https.any.js",
7+
"abs float16 5D tensor",
8+
"onnx",
9+
"PASS",
10+
)

0 commit comments

Comments
 (0)