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

Support for a New CPU ISA #23

Open
willliu opened this issue Jul 27, 2021 · 6 comments
Open

Support for a New CPU ISA #23

willliu opened this issue Jul 27, 2021 · 6 comments

Comments

@willliu
Copy link

willliu commented Jul 27, 2021

Recently I have a new cpu architecture other than the one listed, and build gives the following error:

# github.com/chewxy/math32
../../../../go/pkg/mod/github.com/chewxy/[email protected]/exp.go:3:6: missing function body
../../../../go/pkg/mod/github.com/chewxy/[email protected]/exp.go:57:6: missing function body
../../../../go/pkg/mod/github.com/chewxy/[email protected]/log.go:76:6: missing function body
../../../../go/pkg/mod/github.com/chewxy/[email protected]/remainder.go:33:6: missing function body
../../../../go/pkg/mod/github.com/chewxy/[email protected]/sqrt.go:3:6: missing function body

I am wondering do you have instructions for me to port for this new CPU instruction set, many thanks.

@willliu willliu closed this as completed Jul 29, 2021
@chewxy
Copy link
Owner

chewxy commented Aug 3, 2021

Which CPU arch is that ?

@chewxy chewxy reopened this Aug 3, 2021
@willliu
Copy link
Author

willliu commented Aug 3, 2021

Dear Mr. Chew:

Thank you for your reply. Recently golang team reserves the arch loong64 for loongarch64 CPU ISA. Here is a working and tested modification for a new file stubs_loong64.s:

//+build loong64

#include "textflag.h"

// func Exp(x float32) float32
TEXT ·Exp(SB),NOSPLIT,$0
	JMP ·exp(SB)

// func Exp2(x float32) float32
TEXT ·Exp2(SB),NOSPLIT,$0
	JMP ·exp2(SB)

// func Log(x float32) float32
TEXT ·Log(SB),NOSPLIT,$0
	JMP ·log(SB)

// func Remainder(x, y float32) float32
TEXT ·Remainder(SB),NOSPLIT,$0
	JMP ·remainder(SB)

// func Sqrt(x float32) float32
TEXT ·Sqrt(SB),NOSPLIT,$0
	JMP ·sqrt(SB)

Moreover, I found riscv port may need a modification in the file name. I provide the file stubs_riscv64.s, which is also tested to be working.

#include "textflag.h"

// func Exp(x float32) float32
TEXT ·Exp(SB),NOSPLIT,$0
	JMP ·exp(SB)

// func Exp2(x float32) float32
TEXT ·Exp2(SB),NOSPLIT,$0
	JMP ·exp2(SB)

// func Log(x float32) float32
TEXT ·Log(SB),NOSPLIT,$0
	JMP ·log(SB)

// func Remainder(x, y float32) float32
TEXT ·Remainder(SB),NOSPLIT,$0
	JMP ·remainder(SB)

// func Sqrt(x float32) float32
TEXT ·Sqrt(SB),NOSPLIT,$0
	JMP ·sqrt(SB)

@HougeLangley
Copy link

houge@LoongArch-Gentoo ~ $ go env
GO111MODULE=''
GOARCH='loong64'
GOBIN=''
GOCACHE='/home/houge/.cache/go-build'
GOENV='/home/houge/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='loong64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/houge/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/houge/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/lib/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='local'
GOTOOLDIR='/usr/lib/go/pkg/tool/linux_loong64'
GOVCS=''
GOVERSION='go1.22.2'
GCCGO='gccgo'
AR='ar'
CC='loongarch64-unknown-linux-gnu-gcc'
CXX='loongarch64-unknown-linux-gnu-g++'
CGO_ENABLED='1'
GOMOD='/dev/null'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -mabi=lp64d -pthread -fmessage-length=0 -ffile-prefix-map=/tmp/go-build412895527=/tmp/go-build -gno-record-gcc-switches'

@HougeLangley
Copy link

Screenshot_20240510_074648

@chewxy
Copy link
Owner

chewxy commented May 9, 2024

Send a PR. I will review

@HougeLangley
Copy link

@willliu A friend has submitted a pull request, and when I attempt to compile the latest version, I encounter the following error.

(ollama) houge@LoongArch-Gentoo ~/ollama (main?) $ go get -u github.com/chewxy/math32@7caa3bb
go: downloading github.com/chewxy/math32 v1.10.2-0.20240509203351-7caa3bba2ee1
go: upgraded github.com/chewxy/math32 v1.10.1 => v1.10.2-0.20240509203351-7caa3bba2ee1
(ollama) houge@LoongArch-Gentoo ~/ollama (main*?) $ go build .                                
# github.com/ollama/ollama
/usr/lib/go/pkg/tool/linux_loong64/link: running loongarch64-unknown-linux-gnu-gcc failed: exit status 1
/usr/lib/gcc/loongarch64-unknown-linux-gnu/13/../../../../loongarch64-unknown-linux-gnu/bin/ld: /tmp/go-link-2713671162/000020.o: in function `_cgo_d85a20fb2d9c_Cfunc_llama_model_quantize':
/tmp/go-build/llm.cgo2.c:69:(.text+0x34): undefined reference to `llama_model_quantize'
/usr/lib/gcc/loongarch64-unknown-linux-gnu/13/../../../../loongarch64-unknown-linux-gnu/bin/ld: /tmp/go-link-2713671162/000020.o: in function `_cgo_d85a20fb2d9c_Cfunc_llama_model_quantize_default_params':
/tmp/go-build/llm.cgo2.c:86:(.text+0x98): undefined reference to `llama_model_quantize_default_params'
/usr/lib/gcc/loongarch64-unknown-linux-gnu/13/../../../../loongarch64-unknown-linux-gnu/bin/ld: /tmp/go-link-2713671162/000020.o: in function `_cgo_d85a20fb2d9c_Cfunc_llama_print_system_info':
/tmp/go-build/llm.cgo2.c:103:(.text+0x230): undefined reference to `llama_print_system_info'
collect2: 错误:ld 返回 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants