Skip to content

Commit 9a6dba4

Browse files
committed
Optimized
1 parent 0aa8e38 commit 9a6dba4

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/main.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use progress_bar::color::{Color, Style};
2222
use crate::mono_image::MonoImage;
2323

2424
const DEVICE_TYPE : types::cl_bitfield =
25-
device::CL_DEVICE_TYPE_ALL & !device::CL_DEVICE_TYPE_CPU;
25+
device::CL_DEVICE_TYPE_ALL;
2626

2727
fn main() {
2828
let search_radius_arg =
@@ -204,6 +204,7 @@ fn font(args: &ArgMatches) {
204204
)));
205205

206206
let enable_opencl_workers = !args.is_present("cpu");
207+
let mut cpu_workers_num = num_cpus::get() as i32;
207208

208209
let create_opencl_workers = |platform: Platform| {
209210
let devices =
@@ -214,6 +215,12 @@ fn font(args: &ArgMatches) {
214215

215216
let mut threads = Vec::new();
216217
for device_id in devices {
218+
{
219+
let device = device::Device::new(device_id);
220+
if device.dev_type().unwrap() == device::CL_DEVICE_TYPE_CPU {
221+
cpu_workers_num = 0;
222+
}
223+
}
217224
let progress_bar = progress_bar.clone();
218225
let basic_gen = basic_gen.clone();
219226
let run = run.clone();
@@ -414,8 +421,11 @@ fn font(args: &ArgMatches) {
414421
vec![]
415422
};
416423

424+
cpu_workers_num = cpu_workers_num - (opencl_workers.len() as i32);
425+
cpu_workers_num = cpu_workers_num.clamp(0, i32::MAX);
426+
417427
let cpu_workers : Vec<_> =
418-
(0 .. num_cpus::get() - opencl_workers.len())
428+
(0 .. cpu_workers_num)
419429
.into_iter()
420430
.map(|_| {
421431
let progress_bar = progress_bar.clone();

0 commit comments

Comments
 (0)