-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: codec abstraction and benchmarks
- Loading branch information
Showing
16 changed files
with
260 additions
and
73 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
name: test | ||
|
||
on: | ||
pull_request: | ||
types: [ labeled ] | ||
branches: [ "main" ] | ||
|
||
env: | ||
CARGO_TERM_COLOR: always | ||
RUST_BACKTRACE: 1 | ||
|
||
jobs: | ||
bench: | ||
if: ${{ github.event.label.name == 'bench' }} | ||
|
||
strategy: | ||
fail-fast: false | ||
matrix: | ||
os: [windows-latest, macos-latest] | ||
|
||
runs-on: ${{ matrix.os }} | ||
timeout-minutes: 120 | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/cache@v3 | ||
with: | ||
path: | | ||
~/.cargo/bin/ | ||
~/.cargo/registry/index/ | ||
~/.cargo/registry/cache/ | ||
~/.cargo/git/db/ | ||
target/ | ||
key: ${{ runner.os }}-cargo-build-stable-${{ hashFiles('**/Cargo.toml') }} | ||
|
||
- name: criterion compare | ||
uses: boa-dev/[email protected] | ||
with: | ||
branchName: ${{ github.base_ref }} | ||
token: ${{ secrets.GITHUB_TOKEN }} |
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,47 @@ | ||
use criterion::{ | ||
BenchmarkId, | ||
criterion_group, | ||
criterion_main, | ||
Criterion, | ||
Throughput, | ||
}; | ||
|
||
use bevy_gaussian_splatting::{ | ||
Gaussian, | ||
GaussianCloud, | ||
io::codec::GaussianCloudCodec, | ||
random_gaussians, | ||
}; | ||
|
||
|
||
const GAUSSIAN_COUNTS: [usize; 4] = [ | ||
1000, | ||
10000, | ||
84_348, | ||
1_244_819, | ||
// 6_131_954, | ||
]; | ||
|
||
fn gaussian_cloud_decode_benchmark(c: &mut Criterion) { | ||
let mut group = c.benchmark_group("encode gaussian clouds"); | ||
for count in GAUSSIAN_COUNTS.iter() { | ||
group.throughput(Throughput::Bytes(*count as u64 * std::mem::size_of::<Gaussian>() as u64)); | ||
group.bench_with_input( | ||
BenchmarkId::new("decode", count), | ||
&count, | ||
|b, &count| { | ||
let gaussians = random_gaussians(*count); | ||
let bytes = gaussians.encode(); | ||
|
||
b.iter(|| GaussianCloud::decode(bytes.as_slice())); | ||
}, | ||
); | ||
} | ||
} | ||
|
||
criterion_group!{ | ||
name = io_benches; | ||
config = Criterion::default().sample_size(10); | ||
targets = gaussian_cloud_decode_benchmark | ||
} | ||
criterion_main!(io_benches); |
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,6 @@ | ||
|
||
// TODO: support streamed codecs | ||
pub trait GaussianCloudCodec { | ||
fn encode(&self) -> Vec<u8>; | ||
fn decode(data: &[u8]) -> Self; | ||
} |
Empty file.
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,2 @@ | ||
|
||
|
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,30 @@ | ||
use flexbuffers::{ | ||
FlexbufferSerializer, | ||
Reader, | ||
}; | ||
use serde::{ | ||
Deserialize, | ||
Serialize, | ||
}; | ||
|
||
use crate::{ | ||
GaussianCloud, | ||
io::codec::GaussianCloudCodec, | ||
}; | ||
|
||
|
||
impl GaussianCloudCodec for GaussianCloud { | ||
fn encode(&self) -> Vec<u8> { | ||
let mut serializer = FlexbufferSerializer::new(); | ||
self.serialize(&mut serializer).expect("failed to serialize cloud"); | ||
|
||
serializer.view().to_vec() | ||
} | ||
|
||
fn decode(data: &[u8]) -> Self { | ||
let reader = Reader::get_root(data).expect("failed to read flexbuffer"); | ||
let cloud = GaussianCloud::deserialize(reader).expect("deserialization failed"); | ||
|
||
cloud | ||
} | ||
} |
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,8 @@ | ||
#[cfg(feature = "io_bincode2")] | ||
pub mod bincode2; | ||
|
||
#[cfg(feature = "io_capnp")] | ||
pub mod capnp; | ||
|
||
#[cfg(feature = "io_flexbuffers")] | ||
pub mod flexbuffers; |
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,68 @@ | ||
use std::io::{ | ||
BufReader, | ||
Cursor, | ||
ErrorKind, | ||
}; | ||
|
||
use bevy::{ | ||
asset::{ | ||
AssetLoader, | ||
AsyncReadExt, | ||
LoadContext, | ||
io::Reader, | ||
}, | ||
utils::BoxedFuture, | ||
}; | ||
|
||
use crate::{ | ||
GaussianCloud, | ||
io::{ | ||
codec::GaussianCloudCodec, | ||
ply::parse_ply, | ||
}, | ||
}; | ||
|
||
|
||
#[derive(Default)] | ||
pub struct GaussianCloudLoader; | ||
|
||
impl AssetLoader for GaussianCloudLoader { | ||
type Asset = GaussianCloud; | ||
type Settings = (); | ||
type Error = std::io::Error; | ||
|
||
fn load<'a>( | ||
&'a self, | ||
reader: &'a mut Reader, | ||
_settings: &'a Self::Settings, | ||
load_context: &'a mut LoadContext, | ||
) -> BoxedFuture<'a, Result<Self::Asset, Self::Error>> { | ||
|
||
Box::pin(async move { | ||
let mut bytes = Vec::new(); | ||
reader.read_to_end(&mut bytes).await?; | ||
|
||
match load_context.path().extension() { | ||
Some(ext) if ext == "ply" => { | ||
let cursor = Cursor::new(bytes); | ||
let mut f = BufReader::new(cursor); | ||
|
||
let ply_cloud = parse_ply(&mut f)?; | ||
let cloud = GaussianCloud(ply_cloud); | ||
|
||
Ok(cloud) | ||
}, | ||
Some(ext) if ext == "gcloud" => { | ||
let cloud = GaussianCloud::decode(bytes.as_slice()); | ||
|
||
Ok(cloud) | ||
}, | ||
_ => Err(std::io::Error::new(ErrorKind::Other, "only .ply and .gcloud supported")), | ||
} | ||
}) | ||
} | ||
|
||
fn extensions(&self) -> &[&str] { | ||
&["ply", "gcloud"] | ||
} | ||
} |
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,4 @@ | ||
pub mod codec; | ||
pub mod gcloud; | ||
pub mod loader; | ||
pub mod ply; |
File renamed without changes.
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
Oops, something went wrong.