This repository was archived by the owner on Jan 27, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathuniversal.rs
More file actions
80 lines (67 loc) · 1.88 KB
/
universal.rs
File metadata and controls
80 lines (67 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
use std::path::PathBuf;
use eyre::{Context, Result};
use minijinja::{context, Environment};
use crate::{
config::{Build, Torch},
fileset::FileSet,
torch::kernel_ops_identifier,
};
pub fn write_torch_ext_universal(
env: &Environment,
build: &Build,
target_dir: PathBuf,
ops_id: Option<String>,
) -> Result<FileSet> {
let mut file_set = FileSet::default();
let ops_name = kernel_ops_identifier(&target_dir, &build.general.python_name(), ops_id);
write_ops_py(env, &build.general.python_name(), &ops_name, &mut file_set)?;
write_pyproject_toml(
env,
build.torch.as_ref(),
&build.general.name,
&mut file_set,
)?;
Ok(file_set)
}
fn write_ops_py(
env: &Environment,
name: &str,
ops_name: &str,
file_set: &mut FileSet,
) -> Result<()> {
let mut path = PathBuf::new();
path.push("torch-ext");
path.push(name);
path.push("_ops.py");
let writer = file_set.entry(path);
env.get_template("universal/_ops.py")
.wrap_err("Cannot get _ops-universal.py template")?
.render_to_write(
context! {
ops_name => ops_name,
},
writer,
)
.wrap_err("Cannot render kernel template")?;
Ok(())
}
fn write_pyproject_toml(
env: &Environment,
torch: Option<&Torch>,
name: &str,
file_set: &mut FileSet,
) -> Result<()> {
let writer = file_set.entry("pyproject.toml");
let data_globs = torch.and_then(|torch| torch.data_globs().map(|globs| globs.join(", ")));
env.get_template("universal/pyproject.toml")
.wrap_err("Cannot get universal pyproject.toml template")?
.render_to_write(
context! {
data_globs => data_globs,
name => name,
},
writer,
)
.wrap_err("Cannot render kernel template")?;
Ok(())
}