Fix memory allocation limit

Signed-off-by: trivernis <trivernis@protonmail.com>
pull/1/head
trivernis 4 years ago
parent c093c25946
commit 940c7ff4a0
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -4,8 +4,11 @@
* See LICENSE for more information * See LICENSE for more information
*/ */
use ocl::core::DeviceInfo;
use ocl::enums::DeviceInfoResult;
use ocl::ProQue; use ocl::ProQue;
use parking_lot::Mutex; use parking_lot::Mutex;
use std::mem::size_of;
use std::sync::Arc; use std::sync::Arc;
use std::time::Instant; use std::time::Instant;
@ -19,9 +22,28 @@ impl KernelController {
.src(include_str!("kernel.cl")) .src(include_str!("kernel.cl"))
.dims(1 << 20) .dims(1 << 20)
.build()?; .build()?;
let device = pro_que.device();
println!("Using device {}", device.name()?);
println!("Vendor: {}", device.vendor()?);
println!(
"Global Mem Size: {} bytes",
device.info(DeviceInfo::GlobalMemSize)?
);
println!(
"Max Mem Alloc: {} bytes",
device.info(DeviceInfo::MaxMemAllocSize)?
);
println!();
Ok(Self { pro_que }) Ok(Self { pro_que })
} }
fn available_memory(&self) -> ocl::Result<u64> {
match self.pro_que.device().info(DeviceInfo::GlobalMemSize)? {
DeviceInfoResult::GlobalMemSize(size) => Ok(size),
_ => Ok(0),
}
}
pub fn filter_primes(&self, input: Vec<i64>) -> ocl::Result<Vec<i64>> { pub fn filter_primes(&self, input: Vec<i64>) -> ocl::Result<Vec<i64>> {
lazy_static::lazy_static! {static ref PRIME_CACHE: Arc<Mutex<Vec<i64>>> = Arc::new(Mutex::new(get_lower_primes(2048)));} lazy_static::lazy_static! {static ref PRIME_CACHE: Arc<Mutex<Vec<i64>>> = Arc::new(Mutex::new(get_lower_primes(2048)));}
@ -73,7 +95,8 @@ impl KernelController {
let start = Instant::now(); let start = Instant::now();
let mut prime_cache = PRIME_CACHE.lock(); let mut prime_cache = PRIME_CACHE.lock();
if prime_cache.len() < 1024 * 1024 * 1024 { if (prime_cache.len() + primes.len()) * size_of::<i64>() < self.available_memory()? as usize
{
prime_cache.append(&mut primes.clone()); prime_cache.append(&mut primes.clone());
prime_cache.sort(); prime_cache.sort();
prime_cache.dedup(); prime_cache.dedup();

Loading…
Cancel
Save