-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add skeleton code for 4-bit quantization.
The type is now recognized and I have a very simple quantizer too but no operations are done yet.
- Loading branch information
Showing
7 changed files
with
219 additions
and
57 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,38 @@ | ||
// There is no semaphore in Rust standard library. wat?? | ||
// So I've made a simple one I can use out of a mutex and condition variable.. | ||
|
||
use std::sync::{Arc, Condvar, Mutex, MutexGuard}; | ||
|
||
#[derive(Clone)] | ||
pub struct Semaphore { | ||
count: Arc<Mutex<usize>>, | ||
waiters: Arc<Condvar>, | ||
} | ||
|
||
pub struct SemaphoreGuard<'a> { | ||
mutex_guard: MutexGuard<'a, usize>, | ||
} | ||
|
||
impl<'a> Drop for SemaphoreGuard<'a> { | ||
fn drop(&mut self) { | ||
*self.mutex_guard += 1; | ||
} | ||
} | ||
|
||
impl Semaphore { | ||
pub fn new(count: usize) -> Semaphore { | ||
Semaphore { | ||
count: Arc::new(Mutex::new(count)), | ||
waiters: Arc::new(Condvar::new()), | ||
} | ||
} | ||
|
||
pub fn acquire(&self) -> SemaphoreGuard { | ||
let mut count = self.count.lock().unwrap(); | ||
while *count == 0 { | ||
count = self.waiters.wait(count).unwrap(); | ||
} | ||
*count -= 1; | ||
SemaphoreGuard { mutex_guard: count } | ||
} | ||
} |
Oops, something went wrong.