-
Notifications
You must be signed in to change notification settings - Fork 4
DRAFT: CPU Kernel #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 20 commits
0fbfe21
9b26511
b174811
a48c2fb
2b2722f
0f61852
89173a7
979c243
bfceed3
6753c71
00fb982
51b5774
dfebb59
0198d59
f046bfa
d4b162d
efa779f
1105858
36050c3
115cc36
2e16cb3
8d77224
59726a6
7172491
b5a4a45
4868ad2
81438b5
8a26730
1a14cf9
4726c16
bcfd18c
0f18b25
768bb7e
0d59d32
b60677e
4e296c8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| //! The main entrypoint for running computations. | ||
|
|
||
| use crate::cpu; | ||
| use color_eyre::{eyre::Ok, Result}; | ||
|
|
||
| /// Handles all the computations. | ||
|
|
@@ -30,6 +31,11 @@ pub struct Compute<'compute> { | |
| pub longest_lines: Vec<f32>, | ||
| } | ||
|
|
||
| /// `NUM_CORES` is the physical number of cores on a machine. Currently hardcoded to 8 | ||
| /// as that is what an i9900k has, and is a common configuration. | ||
| /// TODO find a good syscall for this | ||
| const NUM_CORES: usize = 8; | ||
|
|
||
| impl<'compute> Compute<'compute> { | ||
| /// Instantiate. | ||
| pub fn new( | ||
|
|
@@ -76,10 +82,6 @@ impl<'compute> Compute<'compute> { | |
| ..Default::default() | ||
| }; | ||
|
|
||
| #[expect( | ||
| clippy::if_then_some_else_none, | ||
| reason = "The `?` is hard to use in the closure" | ||
| )] | ||
| let vulkan = if matches!(backend, crate::config::Backend::Vulkan) { | ||
| let elevations = dem.elevations.clone(); | ||
| dem.elevations = Vec::new(); // Free up some RAM. | ||
|
|
@@ -189,6 +191,32 @@ impl<'compute> Compute<'compute> { | |
| Vec::new() | ||
| }; | ||
|
|
||
| if matches!(self.backend, crate::config::Backend::CPU) { | ||
| #[expect( | ||
| clippy::as_conversions, | ||
| clippy::cast_possible_truncation, | ||
| reason = "elevations start out as i16s, and i16 -> f32 -> i16 is lossless" | ||
| )] | ||
| let elevations = self | ||
| .dem | ||
| .elevations | ||
| .iter() | ||
| .map(|&x| x as i16) | ||
| .collect::<Vec<i16>>(); | ||
|
|
||
| #[expect(clippy::as_conversions, reason = "u32 -> usize is valid")] | ||
| let surfaces = cpu::multithreaded_kernel( | ||
| &elevations, | ||
| self.dem.max_los_as_points as usize, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can actually just do:
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, can do that |
||
| 360, | ||
| NUM_CORES, | ||
| ); | ||
|
|
||
| self.add_sector_surfaces_to_running_total(&surfaces); | ||
| self.render_total_surfaces()?; | ||
| return Ok(()); | ||
| } | ||
|
|
||
| for angle in 0..crate::axes::SECTOR_STEPS { | ||
| self.load_or_compute_cache(angle)?; | ||
| let mut sector_ring_data = vec![0; self.total_reserved_rings]; | ||
|
|
@@ -537,7 +565,7 @@ pub mod test { | |
| compute.total_surfaces, | ||
| [ | ||
| 2687.689, 2546.9956, 2622.3494, | ||
| 2564.7678, 3231.647, 2239.714, | ||
| 2564.7678, 3231.647, 2239.714, | ||
| 2604.2551, 2186.5012, 1768.3433 | ||
| ] | ||
| ); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that we have a
rust-toolchain.tomlit's enough just to haverustup toolchain install --profile minimalhere and it automatically gets the version from the file. And we don't need the stable toolchain either right?