Skip to content

Commit

Permalink
feat: add logging whether CUDA or OpenCL is used (#71)
Browse files Browse the repository at this point in the history
If your project can run on both, CUDA and OpenCL, it is useful to know
which version is run. To keep the noise low, add debug logging when the
program is created, this should only happen less often then kernel
invocations.
  • Loading branch information
vmx authored Sep 13, 2022
1 parent 26e731d commit 7900e77
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/cuda/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use std::ffi::{c_void, CStr, CString};
use std::fmt;
use std::hash::{Hash, Hasher};

use log::debug;
use rustacuda::memory::{AsyncCopyDestination, DeviceBuffer};
use rustacuda::stream::{Stream, StreamFlags};

Expand Down Expand Up @@ -130,6 +131,7 @@ impl Program {

/// Creates a program for a specific device from a compiled CUDA binary file.
pub fn from_binary(device: &Device, filename: &CStr) -> GPUResult<Program> {
debug!("Creating CUDA program from binary file.");
rustacuda::context::CurrentContext::set_current(&device.context)?;
let module = rustacuda::module::Module::load_from_file(filename).map_err(|err| {
Self::pop_context();
Expand All @@ -151,6 +153,7 @@ impl Program {

/// Creates a program for a specific device from a compiled CUDA binary.
pub fn from_bytes(device: &Device, bytes: &[u8]) -> GPUResult<Program> {
debug!("Creating CUDA program from bytes.");
rustacuda::context::CurrentContext::set_current(&device.context)?;
let module = rustacuda::module::Module::load_from_bytes(bytes).map_err(|err| {
Self::pop_context();
Expand Down
2 changes: 2 additions & 0 deletions src/opencl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ impl Program {

/// Creates a program for a specific device from OpenCL source code.
pub fn from_opencl(device: &Device, src: &str) -> GPUResult<Program> {
debug!("Creating OpenCL program from source.");
let cached = utils::cache_path(device, src)?;
if std::path::Path::exists(&cached) {
let bin = std::fs::read(cached)?;
Expand Down Expand Up @@ -181,6 +182,7 @@ impl Program {

/// Creates a program for a specific device from a compiled OpenCL binary.
pub fn from_binary(device: &Device, bin: Vec<u8>) -> GPUResult<Program> {
debug!("Creating OpenCL program from binary.");
let context = Context::from_device(&device.device)?;
let bins = vec![&bin[..]];
let mut program =
Expand Down

0 comments on commit 7900e77

Please sign in to comment.