Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix collect deps #66

Merged
merged 2 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/core/graph/consteval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ use super::*;

impl Context {
fn collect_deps(&self, node: NodeIdentifier) -> Vec<NodeIdentifier> {
self.dependent_nodes[&node].to_vec()
if self.dependent_nodes.contains_key(&node) {
return self.dependent_nodes[&node].to_vec();
} else {
return vec![];
}
}

pub(crate) fn replace_index(
Expand Down
40 changes: 40 additions & 0 deletions src/core/graph/tests_cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,46 @@ mod tests {
assert_eq!(rust_result[0], 2f32);
}


#[test]
fn test_mul_scalar_consts_and_params() {
let mut ctx = Context::new();

let one = ctx.scalar(1, xla::ElementType::F32).expect("Scalar 1");

let x = ctx.parameter("x", [], xla::ElementType::F32).expect("x");

let product = ctx.mul(x, one).expect("product");

// output XLA
// client must be exposed to the user, it is very nice to control device, memory fraction, and pre-allocation
let client = xla::PjRtClient::cpu().expect("client");//gpu(0.7, false).expect("client");
let name = "test";
/*let executable = ctx.compile(&name, [product], &client).expect("executable");

let x_input = xla::Literal::scalar(2f32);
// args are just provided in the order they are defined, would be nice to pass a dict or something
// a pjrtbuffer is just an array slice on some device
// but im not sure why its a nested vector instead of just one vector
let device_result = executable.execute(&[x_input]).expect("execute");
let host_result = device_result[0][0]
.to_literal_sync()
.expect("to_literal_sync");
let untupled_result = host_result.to_tuple1().expect("untuple");
let rust_result = untupled_result.to_vec::<f32>().expect("to_vec");
println!("{:?}", rust_result);*/
let fold_const = ctx.fold_consts(product, usize::MAX).expect("fold it");
ctx.compile(name, [product], &client).expect("Compile");
println!("{}", ctx.to_string(product));

for (_, val) in ctx.nodes {
println!("{}", val.to_string());
}

assert!(fold_const);
}


#[test]
fn test_mul_add_scalar_consts_and_params() {
let mut ctx = Context::new();
Expand Down
Loading