STRA-338 params h01: routed Down columns (DownColumns), matvec (MatvecDims), grouped GU repeat run
This commit is contained in:
@@ -127,7 +127,7 @@ fn grouped_down(
|
||||
let mut column = context.allocate(10240).unwrap();
|
||||
matrix.copy_from(literal).unwrap();
|
||||
let charge = context.allocated_bytes();
|
||||
context.project_routed_down_columns(&matrix, hidden, &mut output, total, format).unwrap();
|
||||
context.project_routed_down_columns(&matrix, hidden, &mut output, DownColumns { total, format }).unwrap();
|
||||
assert_eq!(context.allocated_bytes(), charge);
|
||||
let mut observed = vec![0; total * 10240];
|
||||
output.copy_to(&mut observed).unwrap();
|
||||
@@ -204,7 +204,7 @@ impl<'c> Refusals<'c> {
|
||||
}
|
||||
|
||||
fn down(&mut self, context: &Context<'_>, total: usize, format: RoutedFormat) -> Result<()> {
|
||||
context.project_routed_down_columns(&self.matrix, &self.input, &mut self.output, total, format)
|
||||
context.project_routed_down_columns(&self.matrix, &self.input, &mut self.output, DownColumns { total, format })
|
||||
}
|
||||
|
||||
fn refuse_shapes(&mut self, device: &Device<'_>, context: &Context<'_>) {
|
||||
@@ -220,7 +220,12 @@ impl<'c> Refusals<'c> {
|
||||
);
|
||||
let short = context.allocate(2556).unwrap();
|
||||
assert_eq!(
|
||||
context.project_routed_down_columns(&self.matrix, &short, &mut self.output, 1, RoutedFormat::IQ4_NL),
|
||||
context.project_routed_down_columns(
|
||||
&self.matrix,
|
||||
&short,
|
||||
&mut self.output,
|
||||
DownColumns { total: 1, format: RoutedFormat::IQ4_NL }
|
||||
),
|
||||
Err(Error::InvalidProjectionShape)
|
||||
);
|
||||
short.release().unwrap();
|
||||
@@ -235,8 +240,7 @@ impl<'c> Refusals<'c> {
|
||||
&self.matrix,
|
||||
&foreign_input,
|
||||
&mut self.output,
|
||||
1,
|
||||
RoutedFormat::IQ4_NL
|
||||
DownColumns { total: 1, format: RoutedFormat::IQ4_NL }
|
||||
),
|
||||
Err(Error::ContextMismatch)
|
||||
);
|
||||
@@ -304,7 +308,10 @@ fn budget_failure(device: &Device<'_>, rig: &Refusals<'_>) {
|
||||
h.copy_from(&rig.valid).unwrap();
|
||||
o.copy_from(&rig.sentinel).unwrap();
|
||||
let charge = small.allocated_bytes();
|
||||
assert_eq!(small.project_routed_down_columns(&w, &h, &mut o, 1, RoutedFormat::IQ4_NL), Err(Error::BudgetExceeded));
|
||||
assert_eq!(
|
||||
small.project_routed_down_columns(&w, &h, &mut o, DownColumns { total: 1, format: RoutedFormat::IQ4_NL }),
|
||||
Err(Error::BudgetExceeded)
|
||||
);
|
||||
assert_eq!(small.allocated_bytes(), charge);
|
||||
let mut after = vec![0; 10240];
|
||||
o.copy_to(&mut after).unwrap();
|
||||
|
||||
@@ -124,6 +124,15 @@ struct Grouped<'a> {
|
||||
down: DeviceBuffer<'a>,
|
||||
}
|
||||
|
||||
/// What the repeat run compares against: the prepared inputs and their sources, the first gate product and the
|
||||
/// transient charge.
|
||||
struct Repeat<'a> {
|
||||
refs: &'a [&'a RoutedGateUpQ8<'a>],
|
||||
inputs: &'a [DeviceBuffer<'a>],
|
||||
first: &'a [u8],
|
||||
charge: usize,
|
||||
}
|
||||
|
||||
impl<'a> Grouped<'a> {
|
||||
fn new(context: &'a Context<'_>, total: usize, zero: bool) -> Result<Self> {
|
||||
let gate = upload(context, &vec![0xa5; total * 2560])?;
|
||||
@@ -148,7 +157,12 @@ impl<'a> Grouped<'a> {
|
||||
actual[2] = read(&self.hidden)?;
|
||||
for (index, down_format) in DOWN_FORMATS.into_iter().enumerate() {
|
||||
let weights = &rig.down_buffers[index];
|
||||
context.project_routed_down_columns(weights, &self.hidden, &mut self.down, self.total, down_format)?;
|
||||
context.project_routed_down_columns(
|
||||
weights,
|
||||
&self.hidden,
|
||||
&mut self.down,
|
||||
DownColumns { total: self.total, format: down_format },
|
||||
)?;
|
||||
actual[index + 3] = read(&self.down)?;
|
||||
}
|
||||
Ok(actual)
|
||||
@@ -159,10 +173,10 @@ impl<'a> Grouped<'a> {
|
||||
mut self,
|
||||
context: &Context<'_>,
|
||||
rig: &GuRig<'_>,
|
||||
(refs, inputs): (&[&RoutedGateUpQ8<'_>], &[DeviceBuffer<'_>]),
|
||||
(first, charge): (&[u8], usize),
|
||||
repeat: Repeat<'_>,
|
||||
checks: &mut Vec<Comparison>,
|
||||
) -> Result<()> {
|
||||
let Repeat { refs, inputs, first, charge } = repeat;
|
||||
self.gate.copy_from(&vec![0x5a; self.total * 2560])?;
|
||||
context.project_routed_gate_up_columns(&rig.gate_weights, refs, &mut self.gate, rig.format)?;
|
||||
checks.push(Comparison {
|
||||
@@ -223,7 +237,12 @@ fn corpus_case(
|
||||
let mut grouped = Grouped::new(context, total, zero)?;
|
||||
let charge = context.allocated_bytes();
|
||||
let actual = grouped.products(context, rig, &refs)?;
|
||||
grouped.verify_and_release(context, rig, (&refs, &inputs), (&actual[0], charge), checks)?;
|
||||
grouped.verify_and_release(
|
||||
context,
|
||||
rig,
|
||||
Repeat { refs: &refs, inputs: &inputs, first: &actual[0], charge },
|
||||
checks,
|
||||
)?;
|
||||
drop(refs);
|
||||
close_owners(prepared)?;
|
||||
release_inputs(inputs)?;
|
||||
|
||||
@@ -177,6 +177,15 @@ struct Grouped<'a> {
|
||||
down: DeviceBuffer<'a>,
|
||||
}
|
||||
|
||||
/// What the repeat run compares against: the prepared inputs and their sources, the first gate product and the
|
||||
/// transient charge.
|
||||
struct Repeat<'a> {
|
||||
refs: &'a [&'a RoutedGateUpQ8<'a>],
|
||||
inputs: &'a [DeviceBuffer<'a>],
|
||||
first: &'a [u8],
|
||||
charge: usize,
|
||||
}
|
||||
|
||||
impl<'a> Grouped<'a> {
|
||||
fn new(context: &'a Context<'_>, total: usize, zero: bool) -> Result<Self> {
|
||||
let gate = upload(context, &vec![0xa5; total * 2560])?;
|
||||
@@ -201,7 +210,12 @@ impl<'a> Grouped<'a> {
|
||||
actual[2] = read(&self.hidden)?;
|
||||
for (index, down_format) in DOWN_FORMATS.into_iter().enumerate() {
|
||||
let weights = &rig.down_buffers[index];
|
||||
context.project_routed_down_columns(weights, &self.hidden, &mut self.down, self.total, down_format)?;
|
||||
context.project_routed_down_columns(
|
||||
weights,
|
||||
&self.hidden,
|
||||
&mut self.down,
|
||||
DownColumns { total: self.total, format: down_format },
|
||||
)?;
|
||||
actual[index + 3] = read(&self.down)?;
|
||||
}
|
||||
Ok(actual)
|
||||
@@ -212,10 +226,10 @@ impl<'a> Grouped<'a> {
|
||||
mut self,
|
||||
context: &Context<'_>,
|
||||
rig: &GuRig<'_>,
|
||||
(refs, inputs): (&[&RoutedGateUpQ8<'_>], &[DeviceBuffer<'_>]),
|
||||
(first, charge): (&[u8], usize),
|
||||
repeat: Repeat<'_>,
|
||||
checks: &mut Vec<Comparison>,
|
||||
) -> Result<()> {
|
||||
let Repeat { refs, inputs, first, charge } = repeat;
|
||||
self.gate.copy_from(&vec![0x5a; self.total * 2560])?;
|
||||
context.project_routed_gate_up_columns(&rig.gate_weights, refs, &mut self.gate, rig.format)?;
|
||||
checks.push(Comparison {
|
||||
@@ -276,7 +290,12 @@ fn corpus_case(
|
||||
let mut grouped = Grouped::new(context, total, zero)?;
|
||||
let charge = context.allocated_bytes();
|
||||
let actual = grouped.products(context, rig, &refs)?;
|
||||
grouped.verify_and_release(context, rig, (&refs, &inputs), (&actual[0], charge), checks)?;
|
||||
grouped.verify_and_release(
|
||||
context,
|
||||
rig,
|
||||
Repeat { refs: &refs, inputs: &inputs, first: &actual[0], charge },
|
||||
checks,
|
||||
)?;
|
||||
drop(refs);
|
||||
close_owners(prepared)?;
|
||||
release_inputs(inputs)?;
|
||||
|
||||
@@ -3,6 +3,13 @@
|
||||
#[allow(unused_imports)]
|
||||
use super::*;
|
||||
|
||||
/// The row and column counts of a matrix-vector product.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub struct MatvecDims {
|
||||
pub rows: usize,
|
||||
pub columns: usize,
|
||||
}
|
||||
|
||||
impl Context<'_> {
|
||||
/// Compute each row's dot product in ascending column order with separate
|
||||
/// binary32 multiply/add rounding. All buffers are exact whole allocations;
|
||||
@@ -12,9 +19,9 @@ impl Context<'_> {
|
||||
matrix: &DeviceBuffer<'_>,
|
||||
vector: &DeviceBuffer<'_>,
|
||||
output: &mut DeviceBuffer<'_>,
|
||||
rows: usize,
|
||||
columns: usize,
|
||||
dims: MatvecDims,
|
||||
) -> Result<()> {
|
||||
let MatvecDims { rows, columns } = dims;
|
||||
let (shape, handles) = self.matvec_admission([matrix, vector, output], rows, columns)?;
|
||||
let [matrix_handle, vector_handle, output_handle] = handles;
|
||||
let mut arguments =
|
||||
|
||||
@@ -75,8 +75,7 @@ impl<'ctx> MmqWeights<'ctx> {
|
||||
NativeWeights::Dual(self),
|
||||
hidden,
|
||||
out,
|
||||
tokens as usize,
|
||||
self.native_format(),
|
||||
DownColumns { total: tokens as usize, format: self.native_format() },
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -51,7 +51,8 @@ fn native_down_owner(
|
||||
input: &DeviceBuffer<'_>,
|
||||
[old, new]: [&mut DeviceBuffer<'_>; 2],
|
||||
) {
|
||||
c.project_routed_down_columns(raw_weight, input, old, 1, raw_format(dual.format)).unwrap();
|
||||
c.project_routed_down_columns(raw_weight, input, old, DownColumns { total: 1, format: raw_format(dual.format) })
|
||||
.unwrap();
|
||||
dual.native_down_columns(input, 1, new).unwrap();
|
||||
same(&download(new, 10240), &download(old, 10240), "dual grouped Down");
|
||||
}
|
||||
|
||||
@@ -1,6 +1,24 @@
|
||||
//! Closed grouped native SwiGLU/Down20/42; each column retains scalar arithmetic.
|
||||
use super::*;
|
||||
type NativeDownCopyHandles = (ffi::BufferHandle, ffi::BufferHandle, ffi::BufferHandle);
|
||||
/// The number of columns and the routed format of one grouped Down projection.
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct DownColumns {
|
||||
pub total: usize,
|
||||
pub format: RoutedFormat,
|
||||
}
|
||||
/// The completed Down output a slot copy reads from: the buffer and its admitted handle.
|
||||
#[derive(Clone, Copy)]
|
||||
struct DownSource<'a, 'b> {
|
||||
buffer: &'a DeviceBuffer<'b>,
|
||||
handle: ffi::BufferHandle,
|
||||
}
|
||||
/// The device scratch of the grouped Down quantization: the Q8 image and the status word.
|
||||
#[derive(Clone, Copy)]
|
||||
struct QuantScratch {
|
||||
q8: ffi::BufferHandle,
|
||||
flag: ffi::BufferHandle,
|
||||
}
|
||||
impl Context<'_> {
|
||||
/// Closed byte transport from completed native Down columns to whole
|
||||
/// disjoint ten-slot packets. Runtime owns the finite/route publication.
|
||||
@@ -30,8 +48,7 @@ impl Context<'_> {
|
||||
handles.try_reserve_exact(total).map_err(|_| Error::HostAllocation)?;
|
||||
for (index, (column, destination, slot)) in copies.iter().enumerate() {
|
||||
let entry = self.admit_down_slot_copy(
|
||||
source,
|
||||
source_handle,
|
||||
DownSource { buffer: source, handle: source_handle },
|
||||
&handles,
|
||||
(index, total),
|
||||
(*column, destination, *slot),
|
||||
@@ -42,12 +59,12 @@ impl Context<'_> {
|
||||
}
|
||||
fn admit_down_slot_copy(
|
||||
&self,
|
||||
source: &DeviceBuffer<'_>,
|
||||
source_handle: ffi::BufferHandle,
|
||||
source: DownSource<'_, '_>,
|
||||
handles: &[NativeDownCopyHandles],
|
||||
(index, total): (usize, usize),
|
||||
(column, destination, slot): (u32, &DeviceBuffer<'_>, u32),
|
||||
) -> Result<NativeDownCopyHandles> {
|
||||
let DownSource { buffer: source, handle: source_handle } = source;
|
||||
if column as usize != index || slot >= 10 || destination.bytes != 102400 {
|
||||
return Err(Error::InvalidProjectionShape);
|
||||
}
|
||||
@@ -131,19 +148,18 @@ impl Context<'_> {
|
||||
weights: &DeviceBuffer<'_>,
|
||||
hidden: &DeviceBuffer<'_>,
|
||||
output: &mut DeviceBuffer<'_>,
|
||||
total: usize,
|
||||
format: RoutedFormat,
|
||||
columns: DownColumns,
|
||||
) -> Result<()> {
|
||||
self.project_routed_down_columns_weight(NativeWeights::Raw(weights), hidden, output, total, format)
|
||||
self.project_routed_down_columns_weight(NativeWeights::Raw(weights), hidden, output, columns)
|
||||
}
|
||||
pub(super) fn project_routed_down_columns_weight(
|
||||
&self,
|
||||
weight_owner: NativeWeights<'_, '_>,
|
||||
hidden: &DeviceBuffer<'_>,
|
||||
output: &mut DeviceBuffer<'_>,
|
||||
total: usize,
|
||||
format: RoutedFormat,
|
||||
columns: DownColumns,
|
||||
) -> Result<()> {
|
||||
let DownColumns { total, format } = columns;
|
||||
let weights = weight_owner.buffer()?;
|
||||
self.grouped_buffers(&[weights, hidden, output])?;
|
||||
let operation = match format {
|
||||
@@ -214,7 +230,7 @@ impl Context<'_> {
|
||||
plan.check_scratch_alias(q8, flag, scratch_bytes)?;
|
||||
status.copy_from(&[0; 4])?;
|
||||
let (quantizer, projector) = self.grouped_down_kernels(plan.operation)?;
|
||||
self.quantize_grouped_down(plan, quantizer, q8, flag, status)?;
|
||||
self.quantize_grouped_down(plan, quantizer, QuantScratch { q8, flag }, status)?;
|
||||
let mut args = ffi::ProjectionArguments::new(plan.handles[0], q8, plan.handles[2], 2560, 640);
|
||||
let guard = self.enter()?;
|
||||
let launch = self.driver.api.launch_grouped_projection(projector.function, 640, plan.total as u32, &mut args);
|
||||
@@ -231,10 +247,10 @@ impl Context<'_> {
|
||||
&self,
|
||||
plan: &GroupedDownPlan,
|
||||
quantizer: FixedKernel,
|
||||
q8: ffi::BufferHandle,
|
||||
flag: ffi::BufferHandle,
|
||||
scratch: QuantScratch,
|
||||
status: &mut DeviceBuffer<'_>,
|
||||
) -> Result<()> {
|
||||
let QuantScratch { q8, flag } = scratch;
|
||||
let total = plan.total;
|
||||
// 640 is a multiple of32: flattening columns preserves every Q8
|
||||
// block, lane schedule, scale/sum and per-column original order.
|
||||
|
||||
@@ -215,6 +215,8 @@ pub use original_verify::{
|
||||
OriginalVerifyRow, OriginalVerifySpan, OriginalVerifyWindow, OriginalVerifyWindowResult,
|
||||
};
|
||||
// Live verifier release/diagnostic owner, profile report and completed-logit readout.
|
||||
#[allow(unused_imports)]
|
||||
pub use impl_context_2::MatvecDims;
|
||||
#[cfg(all(feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_pointer_width = "64"))]
|
||||
#[allow(unused_imports)]
|
||||
pub use impl_devicebuffer::chain_selects_mtp;
|
||||
@@ -232,6 +234,7 @@ pub use impl_devicebuffer::chain_selects_mtp;
|
||||
)))]
|
||||
#[allow(unused_imports)]
|
||||
pub use impl_devicebuffer::set_chain_down_override;
|
||||
pub use moe_group_down_columns::DownColumns;
|
||||
#[cfg(all(feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_pointer_width = "64"))]
|
||||
pub use original_serve_assets::{
|
||||
OriginalAssetKind, OriginalAssetStatus, original_serve_asset_status, original_serve_assets_sealed,
|
||||
|
||||
@@ -98,7 +98,12 @@ fn down_first(
|
||||
io: &mut DownIo<'_, '_>,
|
||||
report: &mut Report,
|
||||
) -> Result<usize> {
|
||||
context.project_routed_down_columns(io.matrix, io.hidden, io.reference, io.total, io.format)?;
|
||||
context.project_routed_down_columns(
|
||||
io.matrix,
|
||||
io.hidden,
|
||||
io.reference,
|
||||
DownColumns { total: io.total, format: io.format },
|
||||
)?;
|
||||
let original = read(io.reference)?;
|
||||
let allocated = context.allocated_bytes();
|
||||
workspace.q8.as_mut().ok_or(Error::ContextPoisoned)?.copy_from(&[0xa5; Q8_BYTES])?;
|
||||
@@ -138,7 +143,12 @@ fn down_fault(
|
||||
) -> Result<()> {
|
||||
io.hidden.copy_from_range(valid.len() - 4, &bits.to_le_bytes())?;
|
||||
let before = read(io.output)?;
|
||||
let old = context.project_routed_down_columns(io.matrix, io.hidden, io.reference, io.total, io.format);
|
||||
let old = context.project_routed_down_columns(
|
||||
io.matrix,
|
||||
io.hidden,
|
||||
io.reference,
|
||||
DownColumns { total: io.total, format: io.format },
|
||||
);
|
||||
let new = workspace.project_down_columns(io.matrix, io.hidden, io.output, io.total, io.format);
|
||||
report.guards += 1;
|
||||
report.refusals +=
|
||||
@@ -161,7 +171,12 @@ fn down_recover(
|
||||
report: &mut Report,
|
||||
) -> Result<()> {
|
||||
io.hidden.copy_from(valid)?;
|
||||
context.project_routed_down_columns(io.matrix, io.hidden, io.reference, io.total, io.format)?;
|
||||
context.project_routed_down_columns(
|
||||
io.matrix,
|
||||
io.hidden,
|
||||
io.reference,
|
||||
DownColumns { total: io.total, format: io.format },
|
||||
)?;
|
||||
let original = read(io.reference)?;
|
||||
workspace.project_down_columns(io.matrix, io.hidden, io.output, io.total, io.format)?;
|
||||
compare(&original, &read(io.output)?, report);
|
||||
|
||||
@@ -102,7 +102,8 @@ fn hidden_down_products(
|
||||
if stop.is_some() {
|
||||
return Ok(stop);
|
||||
}
|
||||
match context.project_routed_down_columns(weights.down, hidden, down, columns.len(), weights.down_format) {
|
||||
let down_columns = DownColumns { total: columns.len(), format: weights.down_format };
|
||||
match context.project_routed_down_columns(weights.down, hidden, down, down_columns) {
|
||||
Ok(()) => {}
|
||||
Err(Error::InvalidQ8Activation) => {
|
||||
return Ok(Some(RoutedResidentRefusal::DownQuant));
|
||||
|
||||
@@ -175,7 +175,10 @@ fn matvec_private_admission_refuses_without_cuda() {
|
||||
let matrix = make(Some(ffi::BufferHandle::synthetic(4)));
|
||||
let vector = make(Some(ffi::BufferHandle::synthetic(8)));
|
||||
let mut output = make(Some(ffi::BufferHandle::synthetic(12)));
|
||||
assert_eq!(context.matvec_f32(&matrix, &vector, &mut output, 1, 1), Err(Error::ContextPoisoned));
|
||||
assert_eq!(
|
||||
context.matvec_f32(&matrix, &vector, &mut output, MatvecDims { rows: 1, columns: 1 }),
|
||||
Err(Error::ContextPoisoned)
|
||||
);
|
||||
// No native context exists in this test. Pure allocation identity and
|
||||
// extent instruments supply the remaining impossible-safe-call cases.
|
||||
assert_eq!(context.allocated_bytes(), 12);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#![cfg(all(feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_pointer_width = "64"))]
|
||||
|
||||
use leleka_cuda_driver::{Context, Device, DeviceBuffer, Driver, Error};
|
||||
use leleka_cuda_driver::{Context, Device, DeviceBuffer, Driver, Error, MatvecDims};
|
||||
|
||||
// Recorded binary32 expectations, independent of wrapper code and PTX output.
|
||||
const ARITHMETIC: &[(&[u32], &[u32], u32)] = &[
|
||||
@@ -128,7 +128,12 @@ fn launch_matvec(
|
||||
output: &mut DeviceBuffer<'_>,
|
||||
) {
|
||||
context
|
||||
.matvec_f32(inputs[0], inputs[1], output, case.matrix.len() / case.vector.len(), case.vector.len())
|
||||
.matvec_f32(
|
||||
inputs[0],
|
||||
inputs[1],
|
||||
output,
|
||||
MatvecDims { rows: case.matrix.len() / case.vector.len(), columns: case.vector.len() },
|
||||
)
|
||||
.expect("installed-driver matvec launch, sync and restoration");
|
||||
}
|
||||
|
||||
@@ -175,7 +180,9 @@ fn shared_input(device: &Device<'_>) {
|
||||
let input = upload(&context, &[1.0, -2.0, 3.0]);
|
||||
let mut output = upload(&context, &[f32::NAN]);
|
||||
assert_eq!(context.allocated_bytes(), 16, "shared input charged once");
|
||||
context.matvec_f32(&input, &input, &mut output, 1, 3).expect("shared immutable input");
|
||||
context
|
||||
.matvec_f32(&input, &input, &mut output, MatvecDims { rows: 1, columns: 3 })
|
||||
.expect("shared immutable input");
|
||||
assert_output(&output, &[14.0]);
|
||||
assert_eq!(read(&input), bytes(&[1.0, -2.0, 3.0]));
|
||||
input.release().expect("shared input free");
|
||||
@@ -188,8 +195,14 @@ fn foreign_refusal(first: &Context<'_>, second: &Context<'_>) {
|
||||
let matrix = upload(first, &[2.0]);
|
||||
let vector = upload(second, &[3.0]);
|
||||
let mut output = upload(second, &[-0.0]);
|
||||
assert_eq!(second.matvec_f32(&matrix, &vector, &mut output, 1, 1), Err(Error::ContextMismatch));
|
||||
assert_eq!(second.matvec_f32(&vector, &vector, &mut output, 0, 1), Err(Error::InvalidMatvecShape));
|
||||
assert_eq!(
|
||||
second.matvec_f32(&matrix, &vector, &mut output, MatvecDims { rows: 1, columns: 1 }),
|
||||
Err(Error::ContextMismatch)
|
||||
);
|
||||
assert_eq!(
|
||||
second.matvec_f32(&vector, &vector, &mut output, MatvecDims { rows: 0, columns: 1 }),
|
||||
Err(Error::InvalidMatvecShape)
|
||||
);
|
||||
assert_eq!(read(&output), bytes(&[-0.0]), "refusals preserve output");
|
||||
assert_eq!(first.allocated_bytes(), 4);
|
||||
assert_eq!(second.allocated_bytes(), 8);
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#[allow(unused_imports)]
|
||||
use super::*;
|
||||
use leleka_cuda_driver::MatvecDims;
|
||||
|
||||
pub(super) fn check_matvec_lengths(f: &mut MatvecFixture<'_>) {
|
||||
for slot in 0..3 {
|
||||
@@ -17,9 +18,9 @@ pub(super) fn check_matvec_bad_length(f: &mut MatvecFixture<'_>, slot: usize, by
|
||||
let before = trace().len();
|
||||
let charged = f.context.allocated_bytes();
|
||||
let error = match slot {
|
||||
0 => f.context.matvec_f32(&bad, &f.b, &mut f.out, f.rows, f.columns),
|
||||
1 => f.context.matvec_f32(&f.a, &bad, &mut f.out, f.rows, f.columns),
|
||||
_ => f.context.matvec_f32(&f.a, &f.b, &mut bad, f.rows, f.columns),
|
||||
0 => f.context.matvec_f32(&bad, &f.b, &mut f.out, MatvecDims { rows: f.rows, columns: f.columns }),
|
||||
1 => f.context.matvec_f32(&f.a, &bad, &mut f.out, MatvecDims { rows: f.rows, columns: f.columns }),
|
||||
_ => f.context.matvec_f32(&f.a, &f.b, &mut bad, MatvecDims { rows: f.rows, columns: f.columns }),
|
||||
};
|
||||
assert_eq!(error, Err(leleka_cuda_driver::Error::InvalidMatvecShape));
|
||||
assert_eq!(trace().len(), before);
|
||||
@@ -104,7 +105,7 @@ pub(super) fn matvec_second_context(device: &leleka_cuda_driver::Device<'_>, f:
|
||||
let mut z = second.allocate(f.out.len()).unwrap();
|
||||
x.copy_from(&f32_bytes(&f.matrix)).unwrap();
|
||||
y.copy_from(&f32_bytes(&f.vector)).unwrap();
|
||||
second.matvec_f32(&x, &y, &mut z, f.rows, f.columns).unwrap();
|
||||
second.matvec_f32(&x, &y, &mut z, MatvecDims { rows: f.rows, columns: f.columns }).unwrap();
|
||||
let mut actual = vec![0; f.rows * 4];
|
||||
z.copy_to(&mut actual).unwrap();
|
||||
check_f32_output(&actual, expected);
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#[allow(unused_imports)]
|
||||
use super::*;
|
||||
use leleka_cuda_driver::MatvecDims;
|
||||
|
||||
pub(super) fn vector_bounds(device: &leleka_cuda_driver::Device<'_>, f: &mut VectorFixture<'_>) {
|
||||
use leleka_cuda_driver::Error;
|
||||
@@ -37,7 +38,10 @@ pub(super) fn vector_poison_refusals(f: &mut VectorFixture<'_>) {
|
||||
use leleka_cuda_driver::Error;
|
||||
let before = trace().len();
|
||||
assert!(vector_call(f).is_err());
|
||||
assert_eq!(f.context.matvec_f32(&f.a, &f.b, &mut f.out, 1, f.count), Err(Error::ContextPoisoned));
|
||||
assert_eq!(
|
||||
f.context.matvec_f32(&f.a, &f.b, &mut f.out, MatvecDims { rows: 1, columns: f.count }),
|
||||
Err(Error::ContextPoisoned)
|
||||
);
|
||||
assert!(f.context.allocate(4).is_err());
|
||||
assert!(f.a.copy_from(&f32_bytes(&f.av)).is_err());
|
||||
assert!(f.context.synchronize().is_err());
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#[allow(unused_imports)]
|
||||
use super::*;
|
||||
use leleka_cuda_driver::MatvecDims;
|
||||
|
||||
pub(super) fn vector_module_context_trace(rows: &[Row]) {
|
||||
for stage in ["load", "lookup", "unload", "launch"] {
|
||||
@@ -75,7 +76,7 @@ pub(super) fn check_arithmetic_fixture(device: &leleka_cuda_driver::Device<'_>,
|
||||
let mut out = context.allocate(4).unwrap();
|
||||
a.copy_from(&f32_bytes(&matrix)).unwrap();
|
||||
b.copy_from(&f32_bytes(&vector)).unwrap();
|
||||
context.matvec_f32(&a, &b, &mut out, 1, vector.len()).unwrap();
|
||||
context.matvec_f32(&a, &b, &mut out, MatvecDims { rows: 1, columns: vector.len() }).unwrap();
|
||||
let mut bytes = [0u8; 4];
|
||||
out.copy_to(&mut bytes).unwrap();
|
||||
check_f32_output(&bytes, &expected);
|
||||
@@ -98,7 +99,8 @@ pub(super) fn matvec_fixture<'a>(context: &'a leleka_cuda_driver::Context<'a>, c
|
||||
MatvecFixture { context, case, a, b, out, matrix, vector, rows, columns }
|
||||
}
|
||||
pub(super) fn matvec_call(f: &mut MatvecFixture<'_>) -> leleka_cuda_driver::Result<()> {
|
||||
f.context.matvec_f32(&f.a, if f.case == "matvec_same_input" { &f.a } else { &f.b }, &mut f.out, f.rows, f.columns)
|
||||
let vector = if f.case == "matvec_same_input" { &f.a } else { &f.b };
|
||||
f.context.matvec_f32(&f.a, vector, &mut f.out, MatvecDims { rows: f.rows, columns: f.columns })
|
||||
}
|
||||
pub(super) fn matvec_child(case: &str) {
|
||||
let driver = Driver::load().unwrap();
|
||||
@@ -150,7 +152,7 @@ pub(super) fn check_matvec_dimensions(f: &mut MatvecFixture<'_>) {
|
||||
(f.rows, 1),
|
||||
];
|
||||
for (m, n) in dimensions {
|
||||
assert!(f.context.matvec_f32(&f.a, &f.b, &mut f.out, m, n).is_err());
|
||||
assert!(f.context.matvec_f32(&f.a, &f.b, &mut f.out, MatvecDims { rows: m, columns: n }).is_err());
|
||||
}
|
||||
assert_eq!(trace().len(), before);
|
||||
assert_eq!(f.context.allocated_bytes(), charged);
|
||||
@@ -162,9 +164,10 @@ pub(super) fn check_matvec_foreign(device: &leleka_cuda_driver::Device<'_>, f: &
|
||||
let b = foreign.allocate(f.b.len()).unwrap();
|
||||
let mut out = foreign.allocate(f.out.len()).unwrap();
|
||||
let before = trace().len();
|
||||
assert_eq!(f.context.matvec_f32(&a, &f.b, &mut f.out, f.rows, f.columns), Err(Error::ContextMismatch));
|
||||
assert_eq!(f.context.matvec_f32(&f.a, &b, &mut f.out, f.rows, f.columns), Err(Error::ContextMismatch));
|
||||
assert_eq!(f.context.matvec_f32(&f.a, &f.b, &mut out, f.rows, f.columns), Err(Error::ContextMismatch));
|
||||
let dims = MatvecDims { rows: f.rows, columns: f.columns };
|
||||
assert_eq!(f.context.matvec_f32(&a, &f.b, &mut f.out, dims), Err(Error::ContextMismatch));
|
||||
assert_eq!(f.context.matvec_f32(&f.a, &b, &mut f.out, dims), Err(Error::ContextMismatch));
|
||||
assert_eq!(f.context.matvec_f32(&f.a, &f.b, &mut out, dims), Err(Error::ContextMismatch));
|
||||
assert_eq!(trace().len(), before);
|
||||
drop((a, b, out));
|
||||
foreign.close().unwrap();
|
||||
|
||||
+6
-1
@@ -174,7 +174,12 @@ pub(super) fn launch_down_plain<'ctx>(
|
||||
format: RoutedFormat,
|
||||
) -> Result<std::result::Result<(), DriverError>> {
|
||||
Ok(match matrix {
|
||||
CachedMoeMatrix::Raw(raw) => context.project_routed_down_columns(raw, input, out, columns, format),
|
||||
CachedMoeMatrix::Raw(raw) => context.project_routed_down_columns(
|
||||
raw,
|
||||
input,
|
||||
out,
|
||||
leleka_cuda_driver::DownColumns { total: columns, format },
|
||||
),
|
||||
CachedMoeMatrix::Dual(actual, owner) => {
|
||||
if dual_routed_format(actual) != format {
|
||||
return Err(Error::IdentityMismatch);
|
||||
|
||||
Reference in New Issue
Block a user