use std::fmt;
use arrow::array::RecordBatch;
use oxidelake_core::params::Predicate;
use oxidelake_core::{BackendKind, DeviceId, EngineError};
use crate::args::{AggregateArgs, FilterProjectArgs, HashJoinArgs, VectorDistanceArgs};
use crate::handles::{DeviceBatch, DeviceBuffer, DeviceStream, HostBuffer};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct MemoryInfo {
pub total_bytes: u64,
pub free_bytes: u64,
pub pinned_supported: bool,
}
impl MemoryInfo {
pub const fn used_bytes(&self) -> u64 {
self.total_bytes.saturating_sub(self.free_bytes)
}
}
pub trait GpuBackend: Send + Sync + fmt::Debug {
fn kind(&self) -> BackendKind;
fn device_id(&self) -> DeviceId;
fn memory_info(&self) -> Result<MemoryInfo, EngineError>;
fn alloc_device(&self, bytes: usize) -> Result<DeviceBuffer, EngineError>;
fn alloc_pinned_host(&self, bytes: usize) -> Result<HostBuffer, EngineError>;
fn create_stream(&self) -> Result<DeviceStream, EngineError>;
fn copy_h2d(
&self,
stream: &DeviceStream,
src: &HostBuffer,
dst: &mut DeviceBuffer,
) -> Result<(), EngineError>;
fn copy_d2h(
&self,
stream: &DeviceStream,
src: &DeviceBuffer,
dst: &mut HostBuffer,
) -> Result<(), EngineError>;
fn synchronize(&self, stream: &DeviceStream) -> Result<(), EngineError>;
fn upload(
&self,
stream: &DeviceStream,
batch: &RecordBatch,
) -> Result<DeviceBatch, EngineError>;
fn download(
&self,
stream: &DeviceStream,
batch: &DeviceBatch,
) -> Result<RecordBatch, EngineError>;
fn filter_project(
&self,
stream: &DeviceStream,
args: FilterProjectArgs<'_>,
) -> Result<DeviceBatch, EngineError>;
fn hash_join(
&self,
stream: &DeviceStream,
args: HashJoinArgs<'_>,
) -> Result<DeviceBatch, EngineError>;
fn aggregate(
&self,
stream: &DeviceStream,
args: AggregateArgs<'_>,
) -> Result<DeviceBatch, EngineError>;
fn vector_distance(
&self,
stream: &DeviceStream,
args: VectorDistanceArgs<'_>,
) -> Result<DeviceBatch, EngineError>;
fn supports_predicate(&self, predicate: &Predicate) -> bool {
let _ = predicate;
true
}
fn supports_hash_join(&self) -> bool {
true
}
fn supports_aggregate(&self) -> bool {
true
}
}