Skip to content

Commit addd8ac

Browse files
committed
Merge branch 'feature/custom-target'
2 parents 64bcddd + f1eb2f0 commit addd8ac

File tree

3 files changed

+132
-0
lines changed

3 files changed

+132
-0
lines changed

openblas-build/src/build.rs

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::{
66
os::unix::io::*,
77
path::*,
88
process::{Command, Stdio},
9+
str::FromStr,
910
};
1011
use walkdir::WalkDir;
1112

@@ -116,6 +117,116 @@ pub enum Target {
116117
Z14,
117118
}
118119

120+
impl FromStr for Target {
121+
type Err = Error;
122+
123+
fn from_str(s: &str) -> Result<Self, Self::Err> {
124+
let target = match s.to_ascii_lowercase().as_str() {
125+
// X86/X86_64 Intel
126+
"p2" => Self::P2,
127+
"katamai" => Self::KATMAI,
128+
"coppermine" => Self::COPPERMINE,
129+
"northwood" => Self::NORTHWOOD,
130+
"prescott" => Self::PRESCOTT,
131+
"banias" => Self::BANIAS,
132+
"yonah" => Self::YONAH,
133+
"core2" => Self::CORE2,
134+
"penryn" => Self::PENRYN,
135+
"dunnington" => Self::DUNNINGTON,
136+
"nehalem" => Self::NEHALEM,
137+
"sandybridge" => Self::SANDYBRIDGE,
138+
"haswell" => Self::HASWELL,
139+
"skylakex" => Self::SKYLAKEX,
140+
"atom" => Self::ATOM,
141+
142+
// X86/X86_64 AMD
143+
"athlon" => Self::ATHLON,
144+
"opteron" => Self::OPTERON,
145+
"opteron_sse3" => Self::OPTERON_SSE3,
146+
"barcelona" => Self::BARCELONA,
147+
"shanghai" => Self::SHANGHAI,
148+
"istanbul" => Self::ISTANBUL,
149+
"bobcat" => Self::BOBCAT,
150+
"bulldozer" => Self::BULLDOZER,
151+
"piledriver" => Self::PILEDRIVER,
152+
"steamroller" => Self::STEAMROLLER,
153+
"excavator" => Self::EXCAVATOR,
154+
"zen" => Self::ZEN,
155+
156+
// X86/X86_64 generic
157+
"sse_generic" => Self::SSE_GENERIC,
158+
"viac3" => Self::VIAC3,
159+
"nano" => Self::NANO,
160+
161+
// Power
162+
"power4" => Self::POWER4,
163+
"power5" => Self::POWER5,
164+
"power6" => Self::POWER6,
165+
"power7" => Self::POWER7,
166+
"power8" => Self::POWER8,
167+
"power9" => Self::POWER9,
168+
"ppcg4" => Self::PPCG4,
169+
"ppc970" => Self::PPC970,
170+
"ppc970mp" => Self::PPC970MP,
171+
"ppc440" => Self::PPC440,
172+
"ppc440fp2" => Self::PPC440FP2,
173+
"cell" => Self::CELL,
174+
175+
// MIPS
176+
"p5600" => Self::P5600,
177+
"mips1004k" => Self::MIPS1004K,
178+
"mips24k" => Self::MIPS24K,
179+
180+
// MIPS64
181+
"sicortex" => Self::SICORTEX,
182+
"loongson3a" => Self::LOONGSON3A,
183+
"loongson3b" => Self::LOONGSON3B,
184+
"i6400" => Self::I6400,
185+
"p6600" => Self::P6600,
186+
"i6500" => Self::I6500,
187+
188+
// IA64
189+
"itanium2" => Self::ITANIUM2,
190+
191+
// Sparc
192+
"sparc" => Self::SPARC,
193+
"sparcv7" => Self::SPARCV7,
194+
195+
// ARM
196+
"cortexa15" => Self::CORTEXA15,
197+
"cortexa9" => Self::CORTEXA9,
198+
"armv7" => Self::ARMV7,
199+
"armv6" => Self::ARMV6,
200+
"armv5" => Self::ARMV5,
201+
202+
// ARM64
203+
"armv8" => Self::ARMV8,
204+
"cortexa53" => Self::CORTEXA53,
205+
"cortexa57" => Self::CORTEXA57,
206+
"cortexa72" => Self::CORTEXA72,
207+
"cortexa73" => Self::CORTEXA73,
208+
"neoversen1" => Self::NEOVERSEN1,
209+
"emag8180" => Self::EMAG8180,
210+
"falkor" => Self::FALKOR,
211+
"thunderx" => Self::THUNDERX,
212+
"thunderx2t99" => Self::THUNDERX2T99,
213+
"tsv110" => Self::TSV110,
214+
215+
// System Z
216+
"zarch_generic" => Self::ZARCH_GENERIC,
217+
"z13" => Self::Z13,
218+
"z14" => Self::Z14,
219+
220+
_ => {
221+
return Err(Error::UnsupportedTarget {
222+
target: s.to_string(),
223+
})
224+
}
225+
};
226+
Ok(target)
227+
}
228+
}
229+
119230
/// make option generator
120231
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
121232
pub struct Configure {
@@ -314,6 +425,15 @@ impl Configure {
314425
mod tests {
315426
use super::*;
316427

428+
#[test]
429+
fn target_from_str() {
430+
assert_eq!(Target::from_str("p2").unwrap(), Target::P2);
431+
assert!(matches!(
432+
Target::from_str("p3").unwrap_err(),
433+
crate::error::Error::UnsupportedTarget { .. }
434+
));
435+
}
436+
317437
#[ignore]
318438
#[test]
319439
fn build_default() {

openblas-build/src/error.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ pub enum Error {
2121
#[error("Library file does not exist: {}", path.display())]
2222
LibraryNotExist { path: PathBuf },
2323

24+
#[error("Target {} is unsupported", target)]
25+
UnsupportedTarget { target: String },
26+
2427
#[error("Other IO errors: {0:?}")]
2528
IOError(#[from] io::Error),
2629
}

openblas-src/build.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,15 @@ fn build() {
104104
} else {
105105
cfg.no_static = true;
106106
}
107+
if let Ok(target) = env::var("OPENBLAS_TARGET") {
108+
cfg.target = Some(
109+
target
110+
.parse()
111+
.expect("Unsupported target is specified by $OPENBLAS_TARGET"),
112+
)
113+
// Do not default to the native target (represented by `cfg.target == None`)
114+
// because most user set `$OPENBLAS_TARGET` explicitly will hope not to use the native target.
115+
}
107116

108117
let output = if feature_enabled("cache") {
109118
use std::{collections::hash_map::DefaultHasher, hash::*};

0 commit comments

Comments
 (0)