-
Notifications
You must be signed in to change notification settings - Fork 0
/
runtime-blas.c
69 lines (54 loc) · 1.36 KB
/
runtime-blas.c
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
#define _GNU_SOURCE
#include "runtime-blas.h"
#include <stdbool.h>
#include "common.h"
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <dlfcn.h>
#if USE_CUDA
cublasHandle_t b2c_cublas_handle;
#endif
runtime_blas_error_t runtime_blas_init(void) {
#if USE_CUDA
return cublasCreate(&b2c_cublas_handle);
#else
return clblasSetup();
#endif
}
runtime_blas_error_t runtime_blas_fini(void) {
#if USE_CUDA
return cublasDestroy(b2c_cublas_handle);
#else
clblasTeardown();
return CL_SUCCESS;
#endif
}
void runtime_blas_xerbla(const char *routine, int arg) {
extern void xerbla_(const char *, int *);
xerbla_(func_name_to_f77(routine), (int[]){arg});
}
const char *func_name_to_f77(const char *func_name) {
static char tbuf[64];
snprintf(tbuf, sizeof tbuf, "%s", func_name);
char *p = NULL;
for (p = &tbuf[0]; *p; p++) {
if (*p == '_')
*p = ' ';
else
*p = toupper(*p);
}
return tbuf;
}
int runtime_blas_lsame(const char *side_p, const char *ch_p) {
extern int lsame_(const char *cha, const char *chb);
return lsame_(side_p, ch_p);
}
void *runtime_blas_func(const char *name) {
void *fptr = dlsym(RTLD_NEXT, name);
if (fptr == NULL) {
writef(STDERR_FILENO, "blas2cuda: failed to lookup '%s': %s\n", name, dlerror());
abort();
}
return fptr;
}