Validation: the compile exchange carries no table handles
What: acceptance::LinkedHandles, CompiledRequest, PipelineRequest::check_handles, the handles
linked_functions returned, the worker's Compiled<P> and CompileResult::Compiled's handles go.
compile_pipeline returns the AcceptancePipeline, a worker compile's result is the pipeline
itself, and linked_functions returns the LinkedFunctions alone.
Why: the handles were the words of the own context's visible-function tables (engine/tables.rs).
Since the deletion of the refused families' arms (e6e70666ed), nothing reads them: every reader
was a check that the worker's handles matched the request, or a test of that check.
Tests: a_request_function_links_the_functions_of_its_libraries,
a_linked_function_is_made_with_the_request_functions_constants and
a_linking_request_crosses_the_exchange_with_its_linked_libraries keep their pipeline and
constant checks and lose the handle-word ones. The product's own tests of
LinkedFunctions::function_handle (engine_tables, engine_argument_tables, engine_recursion,
engine_chosen_pointers) stay.
Nothing an executor enables, binds, submits, reads back or records changes, so the ABI stays
v204: the worker's JSON reply between a parent and its child of one build is all that moved.
This commit is contained in:
1 parent
fe6ed10162
commit
b192b89fa1
7 files changed
+85
-276
No files matched your search
@@ -41,7 +41,7 @@ use metal2vulkan::error::{DescriptorError, Error, RuntimeInput};
|
||||
use metal2vulkan::library::{FunctionConstantValues, Library};
|
||||
use metal2vulkan::pipeline::Stage;
|
||||
use metal2vulkan::pipeline::{
|
||||
ComputePipeline, ComputePipelineDescriptor, FunctionDescriptor, FunctionHandle, LinkedFunction,
|
||||
ComputePipeline, ComputePipelineDescriptor, FunctionDescriptor, LinkedFunction,
|
||||
LinkedFunctions, PrecisionNote, RenderPipeline, RenderPipelineDescriptor, StageModule,
|
||||
StageSource,
|
||||
};
|
||||
@@ -99,21 +99,6 @@ fn stage_precision_notes(stages: &[StageModule]) -> Vec<PrecisionNote> {
|
||||
notes
|
||||
}
|
||||
|
||||
/// The table handle of each function one request function links: by library of
|
||||
/// [`RequestFunction::linked`], then by function of that library's [`LinkedLibrary::functions`],
|
||||
/// what `LinkedFunctions::function_handle` answers for it over the linked functions the compile
|
||||
/// built (`None` where the product gives it none). A visible-function table of the function's stage
|
||||
/// holds these words.
|
||||
pub type LinkedHandles = Vec<Vec<Option<FunctionHandle>>>;
|
||||
|
||||
/// What [`compile_pipeline`] built: the pipeline and, for each of the request's functions
|
||||
/// ([`PipelineRequest::functions`]) in order, the handles of the functions it links.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct CompiledRequest {
|
||||
pub pipeline: AcceptancePipeline,
|
||||
pub handles: Vec<LinkedHandles>,
|
||||
}
|
||||
|
||||
/// An L4 row compiled for a driver: a kernel with the dispatch region its pipeline is created from
|
||||
/// ([`dispatch::plan_compute_row`]), or a render pipeline, created at its stages' default
|
||||
/// specializations, of a `row` function.
|
||||
@@ -458,36 +443,6 @@ impl PipelineRequest {
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Whether `handles` answer this request ([`CompiledRequest::handles`]): one entry per
|
||||
/// function, one list per linked library, one handle per function linked from it.
|
||||
pub fn check_handles(&self, handles: &[LinkedHandles]) -> Result<(), String> {
|
||||
let functions = self.functions();
|
||||
let shape = |linked: &[LinkedLibrary]| {
|
||||
linked
|
||||
.iter()
|
||||
.map(|library| library.functions.len())
|
||||
.collect::<Vec<_>>()
|
||||
};
|
||||
let answered = |handles: &LinkedHandles| handles.iter().map(Vec::len).collect::<Vec<_>>();
|
||||
if functions.len() == handles.len()
|
||||
&& functions
|
||||
.iter()
|
||||
.zip(handles)
|
||||
.all(|(function, handles)| shape(&function.linked) == answered(handles))
|
||||
{
|
||||
Ok(())
|
||||
} else {
|
||||
Err(format!(
|
||||
"the handles {:?} do not answer the linked functions {:?}",
|
||||
handles.iter().map(answered).collect::<Vec<_>>(),
|
||||
functions
|
||||
.iter()
|
||||
.map(|function| shape(&function.linked))
|
||||
.collect::<Vec<_>>()
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Why [`compile_pipeline`] built no pipeline.
|
||||
@@ -577,7 +532,7 @@ pub fn compile_row(
|
||||
constants: FunctionConstantValues::defaults(),
|
||||
};
|
||||
match compile_pipeline(&[bitcode], &request, device, deadline) {
|
||||
Ok(compiled) => RowCompile::of(RowPipeline::of(device, compiled.pipeline, stage)),
|
||||
Ok(pipeline) => RowCompile::of(RowPipeline::of(device, pipeline, stage)),
|
||||
Err(PipelineCompileError::Product(error)) => {
|
||||
RowCompile::NotCompiled(Outcome::from(&error), bounded_detail(&error.to_string()))
|
||||
}
|
||||
@@ -618,9 +573,9 @@ pub fn compile_row_in_worker(
|
||||
compile_compute_request(worker, device, std::slice::from_ref(source), &request).map(
|
||||
|compiled| {
|
||||
(
|
||||
compiled.result.map(|compiled| {
|
||||
AcceptancePipeline::Compute(Box::new(compiled.pipeline))
|
||||
}),
|
||||
compiled
|
||||
.result
|
||||
.map(|pipeline| AcceptancePipeline::Compute(Box::new(pipeline))),
|
||||
compiled.measured,
|
||||
)
|
||||
},
|
||||
@@ -633,9 +588,9 @@ pub fn compile_row_in_worker(
|
||||
compile_render_request(worker, device, std::slice::from_ref(source), &request).map(
|
||||
|compiled| {
|
||||
(
|
||||
compiled.result.map(|compiled| {
|
||||
AcceptancePipeline::Render(Box::new(compiled.pipeline))
|
||||
}),
|
||||
compiled
|
||||
.result
|
||||
.map(|pipeline| AcceptancePipeline::Render(Box::new(pipeline))),
|
||||
compiled.measured,
|
||||
)
|
||||
},
|
||||
@@ -695,7 +650,7 @@ pub fn compile_draw_in_worker(
|
||||
(
|
||||
compiled
|
||||
.result
|
||||
.map(|compiled| AcceptancePipeline::Render(Box::new(compiled.pipeline))),
|
||||
.map(|pipeline| AcceptancePipeline::Render(Box::new(pipeline))),
|
||||
compiled.measured,
|
||||
)
|
||||
});
|
||||
@@ -718,15 +673,13 @@ pub fn retained(bitcode: &[u8]) -> RowSource<'static> {
|
||||
/// orders them, each with the functions it links (from its [`PipelineRequest::linked_ranges`]);
|
||||
/// another number of libraries is [`PipelineCompileError::Libraries`], checked before anything
|
||||
/// decodes. A [`PipelineRequest::Row`] derives its descriptor and companion from the library's AIR
|
||||
/// ([`row`]). With the pipeline come the handles of each function's linked functions, from the
|
||||
/// linked functions the compile built ([`CompiledRequest::handles`]). This is the compile a worker
|
||||
/// runs ([`crate::worker::compile`]); device tests that own their inputs call it in process.
|
||||
/// ([`row`]). This is the compile a worker runs ([`crate::worker::compile`]); device tests that own their inputs call it in process.
|
||||
pub fn compile_pipeline(
|
||||
libraries: &[&[u8]],
|
||||
request: &PipelineRequest,
|
||||
device: &Device,
|
||||
deadline: Option<Instant>,
|
||||
) -> Result<CompiledRequest, PipelineCompileError> {
|
||||
) -> Result<AcceptancePipeline, PipelineCompileError> {
|
||||
let takes = request.libraries();
|
||||
if libraries.len() != takes {
|
||||
return Err(PipelineCompileError::Libraries {
|
||||
@@ -743,7 +696,7 @@ fn compile_counted(
|
||||
request: &PipelineRequest,
|
||||
device: &Device,
|
||||
deadline: Option<Instant>,
|
||||
) -> Result<CompiledRequest, PipelineCompileError> {
|
||||
) -> Result<AcceptancePipeline, PipelineCompileError> {
|
||||
let ranges = request.linked_ranges();
|
||||
// The libraries the `at`-th function of `request.functions()` links (none for a request
|
||||
// whose functions link nothing).
|
||||
@@ -753,19 +706,14 @@ fn compile_counted(
|
||||
DescriptorError::MissingStage { stage },
|
||||
))?;
|
||||
let function = Library::from_air(bitcode).and_then(|library| library.function(&f.entry))?;
|
||||
let (linked, handles) = linked_functions(
|
||||
let linked = linked_functions(
|
||||
libraries.get(linked).unwrap_or_default(),
|
||||
&f.linked,
|
||||
&f.constants,
|
||||
)?;
|
||||
let mut function = FunctionDescriptor::new(function).with_linked(linked);
|
||||
function.constants = f.constants.clone();
|
||||
Ok::<_, Error>((function, handles))
|
||||
};
|
||||
// A request whose functions link nothing (a plain compute, an L4 row) answers no handles.
|
||||
let unlinked = |pipeline| CompiledRequest {
|
||||
pipeline,
|
||||
handles: Vec::new(),
|
||||
Ok::<_, Error>(function)
|
||||
};
|
||||
let budget = Budget::with_deadline(deadline);
|
||||
let render =
|
||||
@@ -778,7 +726,7 @@ fn compile_counted(
|
||||
};
|
||||
Ok(match request {
|
||||
PipelineRequest::Compute { entry, constants } => {
|
||||
let (kernel, _) = function(
|
||||
let kernel = function(
|
||||
0,
|
||||
Stage::Kernel,
|
||||
&RequestFunction::new(entry.as_str(), constants.clone()),
|
||||
@@ -789,7 +737,7 @@ fn compile_counted(
|
||||
&ComputePipelineDescriptor::new(StageSource::Function(kernel)),
|
||||
&budget,
|
||||
)
|
||||
.map(|pipeline| unlinked(AcceptancePipeline::Compute(Box::new(pipeline))))?
|
||||
.map(|pipeline| AcceptancePipeline::Compute(Box::new(pipeline)))?
|
||||
}
|
||||
PipelineRequest::BoundCompute {
|
||||
function: kernel,
|
||||
@@ -798,16 +746,13 @@ fn compile_counted(
|
||||
replay,
|
||||
} => {
|
||||
use crate::candidate::engine::variants;
|
||||
let (kernel, handles) = function(0, Stage::Kernel, kernel, linked(0))?;
|
||||
let kernel = function(0, Stage::Kernel, kernel, linked(0))?;
|
||||
let compile = match replay {
|
||||
true => variants::compile_replay_for_shape,
|
||||
false => variants::compile_compute_for_shape,
|
||||
};
|
||||
let (pipeline, _) = compile(device, &kernel, shape, dispatch.as_ref(), &budget)?;
|
||||
CompiledRequest {
|
||||
pipeline: AcceptancePipeline::Compute(Box::new(pipeline)),
|
||||
handles: vec![handles],
|
||||
}
|
||||
AcceptancePipeline::Compute(Box::new(pipeline))
|
||||
}
|
||||
PipelineRequest::VertexDraw {
|
||||
function: vertex,
|
||||
@@ -815,16 +760,9 @@ fn compile_counted(
|
||||
shape,
|
||||
form,
|
||||
} => {
|
||||
let (vertex, handles) = function(0, Stage::Vertex, vertex, linked(0))?;
|
||||
let vertex = function(0, Stage::Vertex, vertex, linked(0))?;
|
||||
let descriptor = template.descriptor(StageSource::Function(vertex), None)?;
|
||||
CompiledRequest {
|
||||
pipeline: AcceptancePipeline::Render(Box::new(render(
|
||||
&descriptor,
|
||||
shape.as_ref(),
|
||||
*form,
|
||||
)?)),
|
||||
handles: vec![handles],
|
||||
}
|
||||
AcceptancePipeline::Render(Box::new(render(&descriptor, shape.as_ref(), *form)?))
|
||||
}
|
||||
PipelineRequest::Draw {
|
||||
vertex,
|
||||
@@ -832,20 +770,17 @@ fn compile_counted(
|
||||
template,
|
||||
shape,
|
||||
} => {
|
||||
let (vertex, vertex_handles) = function(0, Stage::Vertex, vertex, linked(0))?;
|
||||
let (fragment, fragment_handles) = function(1, Stage::Fragment, fragment, linked(1))?;
|
||||
let vertex = function(0, Stage::Vertex, vertex, linked(0))?;
|
||||
let fragment = function(1, Stage::Fragment, fragment, linked(1))?;
|
||||
let descriptor = template.descriptor(
|
||||
StageSource::Function(vertex),
|
||||
Some(StageSource::Function(fragment)),
|
||||
)?;
|
||||
CompiledRequest {
|
||||
pipeline: AcceptancePipeline::Render(Box::new(render(
|
||||
&descriptor,
|
||||
shape.as_ref(),
|
||||
crate::candidate::engine::variants::DrawForm::Bound,
|
||||
)?)),
|
||||
handles: vec![vertex_handles, fragment_handles],
|
||||
}
|
||||
AcceptancePipeline::Render(Box::new(render(
|
||||
&descriptor,
|
||||
shape.as_ref(),
|
||||
crate::candidate::engine::variants::DrawForm::Bound,
|
||||
)?))
|
||||
}
|
||||
PipelineRequest::MeshDraw {
|
||||
object,
|
||||
@@ -854,11 +789,10 @@ fn compile_counted(
|
||||
template,
|
||||
shape,
|
||||
} => {
|
||||
let mut handles = Vec::new();
|
||||
let mut stages = 0;
|
||||
let mut stage = |f: &MeshFunction, stage: Stage| {
|
||||
let (function, linked_handles) =
|
||||
function(f.library, stage, &f.function, linked(handles.len()))?;
|
||||
handles.push(linked_handles);
|
||||
let function = function(f.library, stage, &f.function, linked(stages))?;
|
||||
stages += 1;
|
||||
Ok::<_, Error>(StageSource::Function(function))
|
||||
};
|
||||
let object = object
|
||||
@@ -883,10 +817,7 @@ fn compile_counted(
|
||||
.0
|
||||
}
|
||||
};
|
||||
CompiledRequest {
|
||||
pipeline: AcceptancePipeline::Render(Box::new(pipeline)),
|
||||
handles,
|
||||
}
|
||||
AcceptancePipeline::Render(Box::new(pipeline))
|
||||
}
|
||||
PipelineRequest::Row {
|
||||
entry,
|
||||
@@ -902,9 +833,8 @@ fn compile_counted(
|
||||
&RequestFunction::new(entry.as_str(), constants.clone()),
|
||||
0..0,
|
||||
)
|
||||
.map(|(function, _)| function)
|
||||
};
|
||||
unlinked(match stage {
|
||||
match stage {
|
||||
RowStage::Kernel => {
|
||||
let mut descriptor =
|
||||
ComputePipelineDescriptor::new(StageSource::Function(own(Stage::Kernel)?));
|
||||
@@ -965,7 +895,7 @@ fn compile_counted(
|
||||
.compile_render_pipeline(&descriptor, &budget)
|
||||
.map(|p| AcceptancePipeline::Render(Box::new(p)))?
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -974,14 +904,12 @@ fn compile_counted(
|
||||
/// bitcode is `libraries`, one each, in the same order: each library decoded once, each of its
|
||||
/// functions in `functions` (the list the Metal oracle puts every linked function into), made with
|
||||
/// the function's constants as `newFunctionWithName:constantValues:` makes it: the compile takes
|
||||
/// the values of the constants its library declares and ignores the others, as Metal does. With
|
||||
/// them come their table handles ([`LinkedHandles`]): each function's
|
||||
/// `LinkedFunctions::function_handle` over the whole list.
|
||||
/// the values of the constants its library declares and ignores the others, as Metal does.
|
||||
pub(crate) fn linked_functions(
|
||||
libraries: &[&[u8]],
|
||||
linked: &[LinkedLibrary],
|
||||
constants: &FunctionConstantValues,
|
||||
) -> Result<(LinkedFunctions, LinkedHandles), Error> {
|
||||
) -> Result<LinkedFunctions, Error> {
|
||||
let mut functions = LinkedFunctions::new();
|
||||
for (library, bitcode) in linked.iter().zip(libraries) {
|
||||
let decoded = Library::from_air(bitcode)?;
|
||||
@@ -991,19 +919,7 @@ pub(crate) fn linked_functions(
|
||||
.with_function(LinkedFunction::new(function).with_constants(constants.clone()));
|
||||
}
|
||||
}
|
||||
// `functions` lists each library's functions in turn, in `linked`'s order.
|
||||
let mut listed = functions.functions.iter();
|
||||
let handles = linked
|
||||
.iter()
|
||||
.map(|library| {
|
||||
listed
|
||||
.by_ref()
|
||||
.take(library.functions.len())
|
||||
.map(|function| functions.function_handle(function))
|
||||
.collect()
|
||||
})
|
||||
.collect();
|
||||
Ok((functions, handles))
|
||||
Ok(functions)
|
||||
}
|
||||
|
||||
/// What the driver did with one pipeline.
|
||||
@@ -1468,7 +1384,7 @@ mod tests {
|
||||
projection: Projection::Derived,
|
||||
constants,
|
||||
};
|
||||
compile_pipeline(&[&vector], &request, &device, None).map(|c| c.pipeline)
|
||||
compile_pipeline(&[&vector], &request, &device, None)
|
||||
};
|
||||
// Undefined, the constant reads its type's zero: Metal makes this pipeline too.
|
||||
match kernel(FunctionConstantValues::defaults()) {
|
||||
@@ -1713,10 +1629,8 @@ mod tests {
|
||||
/// A request function links the functions of its linked libraries: the caller of the public
|
||||
/// linked fixtures compiles only with `linked_scale` and `linked_blend` of the functions
|
||||
/// library and `linked_offset` of its own, the libraries following the stage library in request
|
||||
/// order. With the pipeline come the product's table handles of those functions, by library and
|
||||
/// function in request order: `functions` numbered from 2. A compile given fewer or more
|
||||
/// libraries than the request takes is the tool's exchange error before anything decodes, never
|
||||
/// a product outcome.
|
||||
/// order. A compile given fewer or more libraries than the request takes is the tool's exchange
|
||||
/// error before anything decodes, never a product outcome.
|
||||
#[test]
|
||||
fn a_request_function_links_the_functions_of_its_libraries() {
|
||||
let (Some(caller), Some(functions)) = (
|
||||
@@ -1747,31 +1661,8 @@ mod tests {
|
||||
assert_eq!(linked.libraries(), 3);
|
||||
let libraries = [caller.as_slice(), functions.as_slice(), caller.as_slice()];
|
||||
match compile_pipeline(&libraries, &linked, &device, None) {
|
||||
Ok(CompiledRequest {
|
||||
pipeline: AcceptancePipeline::Compute(pipeline),
|
||||
handles,
|
||||
}) => {
|
||||
Ok(AcceptancePipeline::Compute(pipeline)) => {
|
||||
assert!(pipeline.stage.spirv.len() > 5);
|
||||
linked.check_handles(&handles).unwrap();
|
||||
let words = handles
|
||||
.iter()
|
||||
.map(|function| {
|
||||
function
|
||||
.iter()
|
||||
.map(|library| {
|
||||
library
|
||||
.iter()
|
||||
.map(|h| h.map(FunctionHandle::word))
|
||||
.collect()
|
||||
})
|
||||
.collect()
|
||||
})
|
||||
.collect::<Vec<Vec<Vec<_>>>>();
|
||||
assert_eq!(words, [[vec![Some(2), Some(3)], vec![Some(4)]]]);
|
||||
assert!(linked.check_handles(&[]).is_err());
|
||||
assert!(linked
|
||||
.check_handles(&[vec![handles[0][0].clone()]])
|
||||
.is_err());
|
||||
}
|
||||
other => panic!("the linked caller did not compile: {other:?}"),
|
||||
}
|
||||
@@ -1845,8 +1736,7 @@ mod tests {
|
||||
|
||||
/// Each linked function is made with the request function's constants, as the Metal oracle
|
||||
/// makes it with `newFunctionWithName:constantValues:`: every value, those of constants its
|
||||
/// library does not declare among them, which the compile ignores as Metal does. The table
|
||||
/// handles answer the libraries' functions in order.
|
||||
/// library does not declare among them, which the compile ignores as Metal does.
|
||||
#[test]
|
||||
fn a_linked_function_is_made_with_the_request_functions_constants() {
|
||||
let (Some(declares), Some(declares_none)) = (
|
||||
@@ -1878,18 +1768,7 @@ mod tests {
|
||||
functions: vec!["linked_scale".into(), "linked_blend".into()],
|
||||
},
|
||||
];
|
||||
let (functions, handles) = linked_functions(&libraries, &linked, &constants).unwrap();
|
||||
// Each function's table handle, by library and function.
|
||||
let words = handles
|
||||
.iter()
|
||||
.map(|library| {
|
||||
library
|
||||
.iter()
|
||||
.map(|h| h.map(FunctionHandle::word))
|
||||
.collect()
|
||||
})
|
||||
.collect::<Vec<Vec<_>>>();
|
||||
assert_eq!(words, [vec![Some(2)], vec![Some(3), Some(4)]]);
|
||||
let functions = linked_functions(&libraries, &linked, &constants).unwrap();
|
||||
let taken = functions
|
||||
.functions
|
||||
.iter()
|
||||
|
||||
@@ -1565,7 +1565,7 @@ fn not_compiled(refusal: NotCompiled) -> ExecutorError {
|
||||
/// Compile `case`'s kernel from `library` for `device` in a killable compile worker, as
|
||||
/// [`compute_request`] asks: the product's typed refusal is [`outcome_refusal`]'s, and a stop at
|
||||
/// the worker boundary (the deadline, the memory limit, a crashed worker, an artifact that does not
|
||||
/// load for `device`, handles that do not answer the request) fails the run.
|
||||
/// load for `device`) fails the run.
|
||||
pub fn compile_case(
|
||||
worker: &CompileWorker,
|
||||
device: &WorkerDevice,
|
||||
@@ -1596,8 +1596,7 @@ fn compile_request(
|
||||
#[derive(Debug)]
|
||||
pub enum CompileFailure {
|
||||
/// The worker boundary stopped the compile (the deadline, the memory limit, a crashed
|
||||
/// worker, an artifact that does not load for the device, handles that do not answer the
|
||||
/// request).
|
||||
/// worker, an artifact that does not load for the device).
|
||||
Stopped(WorkerFailure),
|
||||
/// The worker compiled nothing: the product's typed outcome, or inputs the tool does not
|
||||
/// build.
|
||||
@@ -1633,10 +1632,7 @@ impl<P> CompileAttempt<P> {
|
||||
},
|
||||
Ok(compiled) => CompileAttempt {
|
||||
measured: Some(compiled.measured),
|
||||
result: compiled
|
||||
.result
|
||||
.map(|compiled| compiled.pipeline)
|
||||
.map_err(CompileFailure::NotCompiled),
|
||||
result: compiled.result.map_err(CompileFailure::NotCompiled),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -610,8 +610,7 @@ pub(crate) fn compile_in_process(
|
||||
shape: &BindShape,
|
||||
) -> Result<metal2vulkan::pipeline::RenderPipeline, Error> {
|
||||
let (request, bitcode) = draw_request(case, libraries, shape);
|
||||
match crate::acceptance::compile_pipeline(&bitcode, &request, device, None).map(|c| c.pipeline)
|
||||
{
|
||||
match crate::acceptance::compile_pipeline(&bitcode, &request, device, None) {
|
||||
Ok(crate::acceptance::AcceptancePipeline::Render(pipeline)) => Ok(*pipeline),
|
||||
Ok(other) => panic!("a draw compiled to {other:?}"),
|
||||
Err(crate::acceptance::PipelineCompileError::Product(error)) => Err(error),
|
||||
|
||||
@@ -637,7 +637,7 @@ fn descriptor(
|
||||
.iter()
|
||||
.map(|module| module.library.clone())
|
||||
.collect();
|
||||
let (linked, _) = crate::acceptance::linked_functions(&libraries, &linked, &case.constants)
|
||||
let linked = crate::acceptance::linked_functions(&libraries, &linked, &case.constants)
|
||||
.map_err(|error| product_refusal(&error))?;
|
||||
let mut function = FunctionDescriptor::new(function)
|
||||
.with_specialized(true)
|
||||
|
||||
@@ -271,9 +271,8 @@ fn descriptor(
|
||||
.iter()
|
||||
.map(|module| module.library.clone())
|
||||
.collect();
|
||||
let (linked, _) =
|
||||
crate::acceptance::linked_functions(&libraries, &linked, &function.constants)
|
||||
.map_err(|error| product_refusal(&error))?;
|
||||
let linked = crate::acceptance::linked_functions(&libraries, &linked, &function.constants)
|
||||
.map_err(|error| product_refusal(&error))?;
|
||||
let mut made = FunctionDescriptor::new(made)
|
||||
.with_specialized(true)
|
||||
.with_linked(linked);
|
||||
|
||||
@@ -26,16 +26,14 @@
|
||||
//! 4. The child writes the pipeline's cache artifact bytes (`PipelineArtifact::to_bytes`) to the
|
||||
//! file the parent names in [`ARTIFACT_FILE`], a chunk at a time (`PipelineArtifact::write_to`),
|
||||
//! so reporting holds little beside the pipeline: a constant blob the ledger admits is never
|
||||
//! encoded whole in memory, let alone as base64. It reports the artifact's length with the table
|
||||
//! handles of each request function's linked functions ([`crate::acceptance::LinkedHandles`]),
|
||||
//! together with the SHA-256 of the input bytes it decoded and its product fingerprint. The
|
||||
//! encoded whole in memory, let alone as base64. It reports the artifact's length with the
|
||||
//! SHA-256 of the input bytes it decoded and its product fingerprint. The
|
||||
//! parent requires that digest to be its own input's and that fingerprint to be its own (an
|
||||
//! executable rebuilt since the parent started is another compiler, whose pipeline the parent's
|
||||
//! observations would misattribute), requires the file to hold the reported length, decodes the
|
||||
//! bytes with `PipelineArtifact::from_bytes` for the kind it asked for against its own `Device`
|
||||
//! (so bytes of another profile are `WrongDevice`, and stale, corrupt, or other-kind bytes are
|
||||
//! refused), requires the handles to answer its request (`PipelineRequest::check_handles`), and
|
||||
//! re-checks the deadline after decoding.
|
||||
//! refused), and re-checks the deadline after decoding.
|
||||
//! 5. A typed product refusal comes back as its [`Outcome`] (deterministic), a library whose
|
||||
//! source gives no bitcode as the row's outcome (`BitcodeError::attempt`), and pipeline
|
||||
//! inputs the tool does not build for the function as [`NotCompiled::Unmodelled`]; a stop at
|
||||
@@ -51,8 +49,7 @@
|
||||
use super::alloc;
|
||||
use super::{run_json, Measured, ProcessFailure, WorkerFailure, DEADLINE};
|
||||
use crate::acceptance::{
|
||||
compile_pipeline, AcceptancePipeline, CompiledRequest, LinkedHandles, PipelineCompileError,
|
||||
PipelineRequest,
|
||||
compile_pipeline, AcceptancePipeline, PipelineCompileError, PipelineRequest,
|
||||
};
|
||||
use crate::engine::{bounded_detail, Outcome, RowSource};
|
||||
use crate::hash::sha256_bytes;
|
||||
@@ -220,19 +217,11 @@ pub enum NotCompiled {
|
||||
Unmodelled(crate::acceptance::row::Unmodelled),
|
||||
}
|
||||
|
||||
/// A pipeline a worker compiled, with the table handles of the functions each of its request's
|
||||
/// functions links ([`CompiledRequest::handles`]).
|
||||
#[derive(Debug)]
|
||||
pub struct Compiled<P> {
|
||||
pub pipeline: P,
|
||||
pub handles: Vec<LinkedHandles>,
|
||||
}
|
||||
|
||||
/// What one worker compile returned.
|
||||
#[derive(Debug)]
|
||||
pub struct WorkerCompile<P> {
|
||||
/// The pipeline, or why none was built.
|
||||
pub result: Result<Compiled<P>, NotCompiled>,
|
||||
pub result: Result<P, NotCompiled>,
|
||||
/// Peak live heap bytes the compile allocated in the worker (its counting allocator).
|
||||
pub allocator_peak: Option<u64>,
|
||||
/// From preparing the input through decoding the artifact, and the group's peak RSS.
|
||||
@@ -307,12 +296,8 @@ struct CompileOutput {
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
enum CompileResult {
|
||||
/// The length of the pipeline's cache artifact (`PipelineArtifact::to_bytes`), which the
|
||||
/// worker wrote to its [`ARTIFACT_FILE`], and the table handles of each request function's
|
||||
/// linked functions ([`CompiledRequest::handles`]).
|
||||
Compiled {
|
||||
artifact_bytes: u64,
|
||||
handles: Vec<LinkedHandles>,
|
||||
},
|
||||
/// worker wrote to its [`ARTIFACT_FILE`].
|
||||
Compiled { artifact_bytes: u64 },
|
||||
/// The product refused or failed, or a library gave no bitcode: its typed outcome and a
|
||||
/// bounded detail.
|
||||
NotCompiled { outcome: Outcome, detail: String },
|
||||
@@ -363,7 +348,7 @@ fn compile_in<P: PipelineArtifact>(
|
||||
let output = run.result;
|
||||
// The artifact, when the worker reports one; the scratch directory goes once it is read.
|
||||
let artifact = match &output.result {
|
||||
CompileResult::Compiled { artifact_bytes, .. } => {
|
||||
CompileResult::Compiled { artifact_bytes } => {
|
||||
read_artifact(&artifact_path, *artifact_bytes)
|
||||
.map_err(|error| WorkerFailure::Output(error, measured(run.elapsed)))?
|
||||
}
|
||||
@@ -378,15 +363,7 @@ fn compile_in<P: PipelineArtifact>(
|
||||
);
|
||||
// The pipeline holds what it decoded (its blob included), so the bytes go now.
|
||||
drop(artifact);
|
||||
let result = accepted
|
||||
.and_then(|result| match result {
|
||||
Ok(compiled) => request
|
||||
.check_handles(&compiled.handles)
|
||||
.map(|()| Ok(compiled))
|
||||
.map_err(|error| format!("the compile worker's result: {error}")),
|
||||
Err(refused) => Ok(Err(refused)),
|
||||
})
|
||||
.map_err(|error| WorkerFailure::Output(error, measured(run.elapsed)))?;
|
||||
let result = accepted.map_err(|error| WorkerFailure::Output(error, measured(run.elapsed)))?;
|
||||
let measured = measured(run.elapsed);
|
||||
// The deadline covers decoding the result (worker recipe step 3): late is a timeout.
|
||||
if measured.elapsed > DEADLINE {
|
||||
@@ -445,7 +422,7 @@ fn compile_input<'a>(
|
||||
}
|
||||
}
|
||||
|
||||
/// The pipeline of `output` (with its handles) if this product compiled it, it answers the input
|
||||
/// The pipeline of `output` if this product compiled it, it answers the input
|
||||
/// of digest `input_sha256`, and its `artifact` (the bytes the worker wrote) is as long as the
|
||||
/// worker reported and loads for `device` as the kind `P`; an `Err` names why the result cannot
|
||||
/// be used.
|
||||
@@ -454,7 +431,7 @@ fn accept<P: PipelineArtifact>(
|
||||
artifact: &[u8],
|
||||
input_sha256: &str,
|
||||
device: &Device,
|
||||
) -> Result<Result<Compiled<P>, NotCompiled>, String> {
|
||||
) -> Result<Result<P, NotCompiled>, String> {
|
||||
if output.product_fingerprint != TRANSLATOR_FINGERPRINT {
|
||||
return Err(format!(
|
||||
"the compile worker runs product {} and this process product \
|
||||
@@ -473,10 +450,7 @@ fn accept<P: PipelineArtifact>(
|
||||
Ok(Err(NotCompiled::Product(outcome.clone(), detail.clone())))
|
||||
}
|
||||
CompileResult::Unmodelled { reason } => Ok(Err(NotCompiled::Unmodelled(reason.clone()))),
|
||||
CompileResult::Compiled {
|
||||
artifact_bytes,
|
||||
handles,
|
||||
} => {
|
||||
CompileResult::Compiled { artifact_bytes } => {
|
||||
if u64::try_from(artifact.len()).ok() != Some(*artifact_bytes) {
|
||||
return Err(format!(
|
||||
"the compile worker reported a {artifact_bytes}-byte artifact and wrote {} bytes",
|
||||
@@ -484,12 +458,7 @@ fn accept<P: PipelineArtifact>(
|
||||
));
|
||||
}
|
||||
P::from_bytes(artifact, device)
|
||||
.map(|pipeline| {
|
||||
Ok(Compiled {
|
||||
pipeline,
|
||||
handles: handles.clone(),
|
||||
})
|
||||
})
|
||||
.map(Ok)
|
||||
.map_err(artifact_refused)
|
||||
}
|
||||
}
|
||||
@@ -597,7 +566,7 @@ fn serve(
|
||||
)
|
||||
});
|
||||
let result = match compiled {
|
||||
Ok(CompiledRequest { pipeline, handles }) => {
|
||||
Ok(pipeline) => {
|
||||
let mut out = Counted {
|
||||
out: artifact,
|
||||
bytes: 0,
|
||||
@@ -610,7 +579,6 @@ fn serve(
|
||||
.map_err(|error| format!("write the compile worker's artifact: {error}"))?;
|
||||
CompileResult::Compiled {
|
||||
artifact_bytes: out.bytes,
|
||||
handles,
|
||||
}
|
||||
}
|
||||
Err(PipelineCompileError::Product(error)) => not_compiled(&error),
|
||||
@@ -718,11 +686,8 @@ mod tests {
|
||||
serde_json::from_slice(&serde_json::to_vec(&output).unwrap()).unwrap();
|
||||
let pipeline = accept::<ComputePipeline>(&output, &artifact, &digest, device.device())
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
.pipeline;
|
||||
let expected = compile_pipeline(&[&bitcode], &request, device.device(), None)
|
||||
.unwrap()
|
||||
.pipeline;
|
||||
.unwrap();
|
||||
let expected = compile_pipeline(&[&bitcode], &request, device.device(), None).unwrap();
|
||||
let AcceptancePipeline::Compute(expected) = expected else {
|
||||
panic!("a kernel compiles to a compute pipeline");
|
||||
};
|
||||
@@ -749,12 +714,9 @@ mod tests {
|
||||
serde_json::from_slice(&serde_json::to_vec(&output).unwrap()).unwrap();
|
||||
let pipeline = accept::<RenderPipeline>(&output, &artifact, &digest, device.device())
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
.pipeline;
|
||||
.unwrap();
|
||||
let AcceptancePipeline::Render(expected) =
|
||||
compile_pipeline(&[&stage_io], &request, device.device(), None)
|
||||
.unwrap()
|
||||
.pipeline
|
||||
compile_pipeline(&[&stage_io], &request, device.device(), None).unwrap()
|
||||
else {
|
||||
panic!("a vertex function compiles to a vertex-only render pipeline");
|
||||
};
|
||||
@@ -829,12 +791,9 @@ mod tests {
|
||||
serde_json::from_slice(&serde_json::to_vec(&output).unwrap()).unwrap();
|
||||
let pipeline = accept::<ComputePipeline>(&output, &artifact, &digest, device.device())
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
.pipeline;
|
||||
.unwrap();
|
||||
let AcceptancePipeline::Compute(expected) =
|
||||
compile_pipeline(&[&bitcode], &request, device.device(), None)
|
||||
.unwrap()
|
||||
.pipeline
|
||||
compile_pipeline(&[&bitcode], &request, device.device(), None).unwrap()
|
||||
else {
|
||||
panic!("a kernel compiles to a compute pipeline");
|
||||
};
|
||||
@@ -904,12 +863,9 @@ mod tests {
|
||||
serde_json::from_slice(&serde_json::to_vec(&output).unwrap()).unwrap();
|
||||
let pipeline = accept::<RenderPipeline>(&output, &artifact, &digest, device.device())
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
.pipeline;
|
||||
.unwrap();
|
||||
let AcceptancePipeline::Render(expected) =
|
||||
compile_pipeline(&[&bitcode], &request, device.device(), None)
|
||||
.unwrap()
|
||||
.pipeline
|
||||
compile_pipeline(&[&bitcode], &request, device.device(), None).unwrap()
|
||||
else {
|
||||
panic!("a vertex draw compiles to a render pipeline");
|
||||
};
|
||||
@@ -969,12 +925,9 @@ mod tests {
|
||||
serde_json::from_slice(&serde_json::to_vec(&output).unwrap()).unwrap();
|
||||
let pipeline = accept::<RenderPipeline>(&output, &artifact, &digest, device.device())
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
.pipeline;
|
||||
.unwrap();
|
||||
let AcceptancePipeline::Render(expected) =
|
||||
compile_pipeline(&libraries, &request, device.device(), None)
|
||||
.unwrap()
|
||||
.pipeline
|
||||
compile_pipeline(&libraries, &request, device.device(), None).unwrap()
|
||||
else {
|
||||
panic!("a draw compiles to a render pipeline");
|
||||
};
|
||||
@@ -989,9 +942,8 @@ mod tests {
|
||||
}
|
||||
|
||||
/// A kernel's linked libraries cross the exchange after its own: the worker links the functions
|
||||
/// the request names from them into the pipeline the in-process public API compiles, and
|
||||
/// returns the product's table handles of those functions with it; an input without one of them
|
||||
/// is the exchange's error, not a compile.
|
||||
/// the request names from them into the pipeline the in-process public API compiles; an input
|
||||
/// without one of them is the exchange's error, not a compile.
|
||||
#[test]
|
||||
fn a_linking_request_crosses_the_exchange_with_its_linked_libraries() {
|
||||
use crate::acceptance::LinkedLibrary;
|
||||
@@ -1028,12 +980,10 @@ mod tests {
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
let expected = compile_pipeline(&libraries, &request, device.device(), None).unwrap();
|
||||
let AcceptancePipeline::Compute(pipeline) = &expected.pipeline else {
|
||||
let AcceptancePipeline::Compute(pipeline) = &expected else {
|
||||
panic!("a kernel compiles to a compute pipeline");
|
||||
};
|
||||
assert_eq!(&compiled.pipeline, &**pipeline);
|
||||
assert_eq!(compiled.handles, expected.handles);
|
||||
request.check_handles(&compiled.handles).unwrap();
|
||||
assert_eq!(&compiled, &**pipeline);
|
||||
|
||||
let (bytes, _) = libraries_input(&device, &libraries[..2], request);
|
||||
let refused = served(&bytes, Instant::now()).unwrap_err();
|
||||
@@ -1177,12 +1127,9 @@ mod tests {
|
||||
let (output, artifact) = served(&bytes, Instant::now()).unwrap();
|
||||
let pipeline = accept::<ComputePipeline>(&output, &artifact, &digest, device.device())
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
.pipeline;
|
||||
.unwrap();
|
||||
let AcceptancePipeline::Compute(expected) =
|
||||
compile_pipeline(&[&bitcode], &request, device.device(), None)
|
||||
.unwrap()
|
||||
.pipeline
|
||||
compile_pipeline(&[&bitcode], &request, device.device(), None).unwrap()
|
||||
else {
|
||||
panic!("a kernel compiles to a compute pipeline");
|
||||
};
|
||||
@@ -1404,9 +1351,7 @@ mod tests {
|
||||
constants: FunctionConstantValues::defaults(),
|
||||
};
|
||||
let AcceptancePipeline::Compute(expected) =
|
||||
compile_pipeline(&[&bitcode], &request, device.device(), None)
|
||||
.unwrap()
|
||||
.pipeline
|
||||
compile_pipeline(&[&bitcode], &request, device.device(), None).unwrap()
|
||||
else {
|
||||
panic!("a kernel compiles to a compute pipeline");
|
||||
};
|
||||
@@ -1419,8 +1364,7 @@ mod tests {
|
||||
)
|
||||
.unwrap_or_else(|failure| panic!("{}", failure.message()));
|
||||
let pipeline = compiled.result.unwrap();
|
||||
assert_eq!(pipeline.pipeline, *expected);
|
||||
assert!(pipeline.handles.is_empty());
|
||||
assert_eq!(pipeline, *expected);
|
||||
assert!(compiled.allocator_peak.is_some_and(|peak| peak > 0));
|
||||
assert!(compiled.measured.elapsed < DEADLINE);
|
||||
if cfg!(any(target_os = "macos", target_os = "linux")) {
|
||||
|
||||
@@ -63,9 +63,7 @@ fn every_device_tool_serves_the_compile_worker_with_the_public_apis_pipeline() {
|
||||
constants: FunctionConstantValues::defaults(),
|
||||
};
|
||||
let AcceptancePipeline::Compute(expected) =
|
||||
compile_pipeline(&[&bitcode], &request, device.device(), None)
|
||||
.unwrap()
|
||||
.pipeline
|
||||
compile_pipeline(&[&bitcode], &request, device.device(), None).unwrap()
|
||||
else {
|
||||
panic!("a kernel compiles to a compute pipeline");
|
||||
};
|
||||
@@ -81,8 +79,7 @@ fn every_device_tool_serves_the_compile_worker_with_the_public_apis_pipeline() {
|
||||
)
|
||||
.unwrap_or_else(|failure| panic!("{program}: {}", failure.message()));
|
||||
let compiled_pipeline = compiled.result.unwrap();
|
||||
assert_eq!(compiled_pipeline.pipeline, *expected, "{program}");
|
||||
assert!(compiled_pipeline.handles.is_empty(), "{program}");
|
||||
assert_eq!(compiled_pipeline, *expected, "{program}");
|
||||
assert!(
|
||||
compiled.allocator_peak.is_some_and(|peak| peak > 0),
|
||||
"{program}"
|
||||
@@ -128,9 +125,7 @@ fn a_logged_draw_compiles_in_the_worker_as_in_process() {
|
||||
shape: None,
|
||||
};
|
||||
let AcceptancePipeline::Render(expected) =
|
||||
compile_pipeline(&[&bitcode, &bitcode], &request, device.device(), None)
|
||||
.unwrap()
|
||||
.pipeline
|
||||
compile_pipeline(&[&bitcode, &bitcode], &request, device.device(), None).unwrap()
|
||||
else {
|
||||
panic!("a draw compiles to a render pipeline");
|
||||
};
|
||||
@@ -178,9 +173,7 @@ fn a_vertex_function_and_a_refusal_cross_the_worker_boundary() {
|
||||
constants: FunctionConstantValues::defaults(),
|
||||
};
|
||||
let AcceptancePipeline::Render(expected) =
|
||||
compile_pipeline(&[&bitcode], &request, device.device(), None)
|
||||
.unwrap()
|
||||
.pipeline
|
||||
compile_pipeline(&[&bitcode], &request, device.device(), None).unwrap()
|
||||
else {
|
||||
panic!("{entry} compiles to a render pipeline");
|
||||
};
|
||||
@@ -305,7 +298,6 @@ fn compile_blob(depth: u32) -> (WorkerCompile<ComputePipeline>, u64) {
|
||||
.unwrap_or_else(|failure| panic!("{depth} levels: {}", failure.message()));
|
||||
let blob = match &compiled.result {
|
||||
Ok(compiled) => compiled
|
||||
.pipeline
|
||||
.stage
|
||||
.constant_blob
|
||||
.as_ref()
|
||||
|
||||
Reference in new issue
Block a user