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

Add support for using a custom target under linux Fixes #18 #78

Merged

Conversation

nemosupremo
Copy link
Contributor

This allows the requested target to be specified by the environment variable OPENBLAS_TARGET under linux. This fixes #18

Copy link
Member

@IvanUkhov IvanUkhov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to get input from termoshtt.

@@ -2,10 +2,11 @@

use crate::{check::*, error::*};
use std::{
fs,
fmt, fs,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please run rustfmt.


fn from_str(s: &str) -> Result<Self, Self::Err> {
let target = match s.to_ascii_lowercase().as_str() {
"p2" => Self::P2,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please also split it into sections with titles just like in the enum? To keep things synced.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

e3fa176 comment added


impl fmt::Display for ParseTargetError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
"provided string was not a valid target".fmt(f)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deviates from the other error messages. Maybe “The target is not supported.”?

}
}

#[derive(Debug, Clone, PartialEq, Eq, Default)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sort these.

pub struct ParseTargetError;

impl fmt::Display for ParseTargetError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please call it formatter.

impl FromStr for Target {
type Err = ParseTargetError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please call it string or value.

@@ -116,6 +117,99 @@ pub enum Target {
Z14,
}

impl FromStr for Target {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would probably generate both the enum and this impl via a macro to avoid repetition. But if cumbersome, let’s keep it as is.

@@ -104,6 +104,10 @@ fn build() {
} else {
cfg.no_static = true;
}
cfg.target = match env::var("OPENBLAS_TARGET") {
Ok(target) => target.parse().ok(),
Copy link
Member

@IvanUkhov IvanUkhov Sep 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that the error is ignored, I propose to remove ParseTargetError all together. Just use some existing struct to satisfy the trait.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ParseTargetError is merged in openblas_build::error::Error::UnsupportedTarget cee2fd0

cfg.target = match env::var("OPENBLAS_TARGET") {
Ok(target) => target.parse().ok(),
_ => None,
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I change here in e25b20f to immediately panic when $OPENBLAS_TARGET is invalid.

@termoshtt
Copy link
Member

@termoshtt termoshtt merged commit 677ff02 into blas-lapack-rs:master Sep 19, 2021
termoshtt added a commit that referenced this pull request Aug 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

OpenBLAS v0.2.19 cannot detect correct CPU
3 participants