border_candle_agent/
lib.rspub mod cnn;
pub mod dqn;
pub mod mlp;
pub mod model;
pub mod opt;
pub mod sac;
mod tensor_batch;
pub mod util;
use candle_core::{backend::BackendDevice, DeviceLocation};
use serde::{Deserialize, Serialize};
pub use tensor_batch::{TensorBatch, ZeroTensor};
#[derive(Clone, Debug, Copy, Deserialize, Serialize, PartialEq)]
pub enum Device {
Cpu,
Cuda(usize),
}
impl From<candle_core::Device> for Device {
fn from(device: candle_core::Device) -> Self {
match device {
candle_core::Device::Cpu => Self::Cpu,
candle_core::Device::Cuda(cuda_device) => {
let loc = cuda_device.location();
match loc {
DeviceLocation::Cuda { gpu_id } => Self::Cuda(gpu_id),
_ => panic!(),
}
}
_ => unimplemented!(),
}
}
}
impl Into<candle_core::Device> for Device {
fn into(self) -> candle_core::Device {
match self {
Self::Cpu => candle_core::Device::Cpu,
Self::Cuda(n) => candle_core::Device::new_cuda(n).unwrap(),
}
}
}