pub trait TensorRngPrims<Alg: Algebra> {
type Plan;
type Context;
// Required methods
fn plan(
ctx: &mut Self::Context,
desc: &RngPrimsDescriptor,
shapes: &[&[usize]],
) -> Result<Self::Plan>;
fn execute(
ctx: &mut Self::Context,
plan: &Self::Plan,
generator: &mut Generator,
output: &mut Tensor<Alg::Scalar>,
) -> Result<()>;
fn has_rng_support(desc: RngPrimsDescriptor) -> bool;
}Expand description
Tensor RNG execution family.
The family is plan/execute based like the rest of tenferro-prims, but the
plan is intentionally small: it only records the descriptor and the output
shape so the execution side can validate the destination tensor before
writing into it.
§Examples
ⓘ
use tenferro_algebra::Standard;
use tenferro_device::Generator;
use tenferro_prims::{CpuBackend, CpuContext, RngPrimsDescriptor, TensorRngPrims};
use tenferro_tensor::{MemoryOrder, Tensor};
let mut ctx = CpuContext::new(1);
let mut generator = Generator::cpu(1234);
let desc = RngPrimsDescriptor::Uniform;
let mut output = Tensor::<f64>::zeros(
&[8],
tenferro_device::LogicalMemorySpace::MainMemory,
MemoryOrder::ColumnMajor,
).unwrap();
let plan = <CpuBackend as TensorRngPrims<Standard<f64>>>::plan(
&mut ctx,
&desc,
&[output.dims()],
).unwrap();
<CpuBackend as TensorRngPrims<Standard<f64>>>::execute(
&mut ctx,
&plan,
&mut generator,
&mut output,
).unwrap();Required Associated Types§
Required Methods§
Sourcefn plan(
ctx: &mut Self::Context,
desc: &RngPrimsDescriptor,
shapes: &[&[usize]],
) -> Result<Self::Plan>
fn plan( ctx: &mut Self::Context, desc: &RngPrimsDescriptor, shapes: &[&[usize]], ) -> Result<Self::Plan>
Plan a tensor RNG operation for the given output shape.
Sourcefn execute(
ctx: &mut Self::Context,
plan: &Self::Plan,
generator: &mut Generator,
output: &mut Tensor<Alg::Scalar>,
) -> Result<()>
fn execute( ctx: &mut Self::Context, plan: &Self::Plan, generator: &mut Generator, output: &mut Tensor<Alg::Scalar>, ) -> Result<()>
Execute a previously planned RNG operation.
Sourcefn has_rng_support(desc: RngPrimsDescriptor) -> bool
fn has_rng_support(desc: RngPrimsDescriptor) -> bool
Report whether the backend advertises support for the given descriptor.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementors§
Source§impl TensorRngPrims<Standard<f64>> for CpuBackend
impl TensorRngPrims<Standard<f64>> for CpuBackend
type Plan = (RngPrimsDescriptor, Vec<usize>)
type Context = CpuContext
Source§impl TensorRngPrims<Standard<f64>> for CudaBackend
Available on non-crate feature cuda only.
impl TensorRngPrims<Standard<f64>> for CudaBackend
Available on non-crate feature
cuda only.type Plan = (RngPrimsDescriptor, Vec<usize>)
type Context = CudaContext
Source§impl TensorRngPrims<Standard<f64>> for RocmBackend
impl TensorRngPrims<Standard<f64>> for RocmBackend
type Plan = (RngPrimsDescriptor, Vec<usize>)
type Context = RocmContext
Source§impl TensorRngPrims<Standard<i32>> for CpuBackend
impl TensorRngPrims<Standard<i32>> for CpuBackend
type Plan = (RngPrimsDescriptor, Vec<usize>)
type Context = CpuContext
Source§impl TensorRngPrims<Standard<i32>> for CudaBackend
Available on non-crate feature cuda only.
impl TensorRngPrims<Standard<i32>> for CudaBackend
Available on non-crate feature
cuda only.