-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
LBT_FORCE_*
environment variable overrides
This provides a flexible mechanism through which LBT's autodetection facilities can be overridden. It enables debugging strange behaviors without needing to recompile LBT from scratch to disable a certain layer of its behavior.
- Loading branch information
1 parent
48f2cf6
commit 07c3509
Showing
8 changed files
with
151 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#include "libblastrampoline_internal.h" | ||
#include <ctype.h> | ||
|
||
const char * env_lowercase(const char * env_name) { | ||
// Get environment value, if it's not set, return false | ||
char * env_value = getenv(env_name); | ||
if (env_value == NULL) { | ||
return NULL; | ||
} | ||
|
||
// If it is set, convert to lowercase. | ||
env_value = strdup(env_value); | ||
for (size_t idx=0; idx<strlen(env_value); ++idx) { | ||
env_value[idx] = tolower(env_value[idx]); | ||
} | ||
return env_value; | ||
} | ||
|
||
|
||
uint8_t env_lowercase_match(const char * env_name, const char * value) { | ||
const char * env_value = env_lowercase(env_name); | ||
if (env_value == NULL) { | ||
return 0; | ||
} | ||
|
||
int ret = strcmp(env_value, value) == 0; | ||
free((void *)env_value); | ||
return ret; | ||
} | ||
|
||
uint8_t env_lowercase_match_any(const char * env_name, uint32_t num_values, ...) { | ||
va_list args; | ||
va_start(args, num_values); | ||
|
||
// Get environment value | ||
const char * env_value = env_lowercase(env_name); | ||
if (env_value == NULL) { | ||
return 0; | ||
} | ||
|
||
// Search through our varargs for a match | ||
for (uint32_t idx=0; idx<num_values; idx++ ) { | ||
const char *value = va_arg(args, const char *); | ||
if (strcmp(env_value, value) == 0) { | ||
free((void *)env_value); | ||
return 1; | ||
} | ||
} | ||
free((void *)env_value); | ||
return 0; | ||
} | ||
|
||
// Check to see if `env_name` matches any "boolean"-like | ||
uint8_t env_match_bool(const char * env_name, uint8_t default_value) { | ||
if (env_lowercase_match_any(env_name, 3, "0", "false", "no")) { | ||
return 0; | ||
} | ||
if (env_lowercase_match_any(env_name, 3, "1", "true", "yes")) { | ||
return 1; | ||
} | ||
return default_value; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
include ../../src/Make.inc | ||
|
||
all: $(prefix)/isamax_test$(EXE) | ||
|
||
$(prefix): | ||
@mkdir -p $@ | ||
|
||
$(prefix)/isamax_test$(EXE): isamax_test.c | $(prefix) | ||
@$(CC) -o $@ $(CFLAGS) $^ $(LDFLAGS) | ||
|
||
clean: | ||
@rm -f $(prefix)/isamax_test$(EXE) | ||
|
||
run: $(prefix)/isamax_test$(EXE) | ||
@$(prefix)/isamax_test$(EXE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#include <stdio.h> | ||
#include <stdint.h> | ||
|
||
extern int64_t isamax_64_(int64_t *, float *, int64_t *); | ||
|
||
#define N 4 | ||
int main() | ||
{ | ||
int64_t n = 0xffffffff00000003; | ||
float X[3] = {1.0f, 2.0f, 1.0f}; | ||
int64_t incx = 1; | ||
|
||
int64_t max_idx = isamax_64_(&n, X, &incx); | ||
printf("max_idx: %lld\n", max_idx); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters