Skip to content

Commit 531ac9e

Browse files
committed
blas
1 parent 056c1e2 commit 531ac9e

2 files changed

Lines changed: 40 additions & 4 deletions

File tree

k+/l.c

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,46 @@ void reg(int64_t id, int64_t name, int32_t arity){
44
dx(Asn(sc(Ku(name)),l));
55
}
66
void libs(void){ //encode strings with: https://play.golang.org/p/4ethx6OEVCR
7-
reg(0,846033518ull,1); //nrm2
7+
#ifdef BLAS
8+
reg(0, 846033518ull,1); //nrm2
9+
reg(1,1836413793ull,1); //asum
10+
reg(2,2019650921ull,1); //imax
11+
#endif
812
//reg(1,...);
913
//reg(2,...);
1014
}
15+
int64_t fzvec(int64_t x){
16+
int32_t xt=tp(x);
17+
if(xt<16){x=Enl(x);xt=tp(x);}
18+
if(xt<Ft){x=Add(Kf(0.0),x);}
19+
if(xt>Zt)trap();
20+
return x;
21+
}
22+
23+
#ifdef BLAS
24+
double cblas_dnrm2(int,double*,int);
25+
double cblas_dasum(int,double*,int);
26+
int cblas_idamax(int,double*,int);
27+
int cblas_izamax(int,double*,int);
28+
#endif
29+
30+
#define fp(x) ((double*)(M_+(int32_t)x))
31+
1132
int64_t cnative(int64_t x, int64_t y){
33+
int32_t xt,xn,i;
34+
double r;
1235
switch(x){ //switch registered function id
13-
case 0: printf("todo call blas nrm2\n"); return y; break;
36+
#ifdef BLAS
37+
case 0:x=fzvec(Fst(y));xn=nn(x);if(xt==Zt)xn*=2;
38+
r=cblas_dnrm2(xn,fp(x),1);
39+
dx(x);return Kf(r);
40+
case 1:x=fzvec(Fst(y));xn=nn(x);if(xt==Zt)xn*=2;
41+
r=cblas_dasum(xn,fp(x),1);
42+
dx(x);return Kf(r);
43+
case 2:x=fzvec(Fst(y));xn=nn(x);
44+
i=tp(x)==Ft?cblas_idamax(xn,fp(x),1):cblas_izamax(xn,fp(x),1);
45+
dx(x);return Ki(i);
46+
#endif
1447
default: return y;
1548
}}
1649

k+/readme

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33

44
set -e
55
set -x
6-
CC=cc
76
if [ "$1" = "get" ];then
87
wget -Okc.orig https://github.com/ktye/i/releases/download/latest/k.c
98
fi
109

1110
sed -e 's/math.h>$/math.h>\n#include"l.h"/' -e 's/kinit()/kinit();libs()/' kc.orig>k.c
1211
cat l.c >>k.c
1312

14-
$CC -O3 -march=native -ok+ k.c -lm
13+
CC=cc
14+
DD="-D BLAS"
15+
16+
17+
$CC -O3 -march=native -ok+ $DD k.c -lopenblas -lm

0 commit comments

Comments
 (0)