whisper.cpp icon indicating copy to clipboard operation
whisper.cpp copied to clipboard

Panic when using go binding with CUDA compiled library

Open thepacketloss opened this issue 1 year ago • 4 comments

I'm trying to use cuda with go binding and I get this error randomly : I already saw this issue : https://github.com/ggerganov/whisper.cpp/issues/1814 and I'm using master branch already tested v1.5.4 and v1.5.1

GGML_ASSERT: ggml-cuda.cu:7730: ptr == (void *) (g_cuda_pool_addr[device] + g_cuda_pool_used[device])
SIGABRT: abort
PC=0x7710734ab32c m=8 sigcode=18446744073709551610
signal arrived during cgo execution

goroutine 7261 gp=0xc0004cc700 m=8 mp=0xc000500008 [syscall]:
runtime.cgocall(0xd974d0, 0xc0000938b8)
        /usr/lib/go/src/runtime/cgocall.go:157 +0x4b fp=0xc000093890 sp=0xc000093858 pc=0x42e54b
github.com/ggerganov/whisper.cpp/bindings/go._Cfunc_whisper_full(0x3bae490, {0x0, 0xc, 0x4000, 0x0, 0x0, 0x0, 0x1, 0x0, 0x1, ...}, ...)
        _cgo_gotypes.go:315 +0x4e fp=0xc0000938b8 sp=0xc000093890 pc=0xd6a58e
github.com/ggerganov/whisper.cpp/bindings/go.(*Context).Whisper_full.func1(0x3bae490, 0xc0001185a0?, {0xc0009b4000, 0x7710714eef28?, 0x10?})
        /home/masoud/go/pkg/mod/github.com/ggerganov/whisper.cpp/bindings/[email protected]/whisper.go:317 +0x11f fp=0xc000093bf8 sp=0xc0000938b8 pc=0xd6eedf
github.com/ggerganov/whisper.cpp/bindings/go.(*Context).Whisper_full(_, {0x0, 0xc, 0x4000, 0x0, 0x0, 0x0, 0x1, 0x0, 0x1, ...}, ...)
        /home/masoud/go/pkg/mod/github.com/ggerganov/whisper.cpp/bindings/[email protected]/whisper.go:317 +0x267 fp=0xc000093c90 sp=0xc000093bf8 pc=0xd6ec67
github.com/ggerganov/whisper.cpp/bindings/go/pkg/whisper.(*context).Process(0xc00011a360, {0xc0009b4000, 0x1c020, 0x22000}, 0x1084628, 0x0)
        /home/masoud/go/pkg/mod/github.com/ggerganov/whisper.cpp/bindings/[email protected]/pkg/whisper/context.go:196 +0x185 fp=0xc000093ee0 sp=0xc000093c90 pc=0xd73645
main.transcribe({0xc000796000, 0x38040, 0x3a000})
        /home/masoud/Desktop/citra_transcriber/whisper.go:82 +0x282 fp=0xc000093fb8 sp=0xc000093ee0 pc=0xd7cd42

Here is my code :

func pcmToFloat32(pcmData []byte) []float32 {
	var floatData []float32
	buffer := bytes.NewBuffer(pcmData)
	for buffer.Len() >= 2 {
		var sample int16
		binary.Read(buffer, binary.LittleEndian, &sample)
		floatSample := float32(sample) / float32(1<<15)
		floatData = append(floatData, floatSample)
	}
	return floatData
}

func transcribe(buf []byte) {
	var data = pcmToFloat32(buf)
	ctx, err := Model.NewContext()
	if err != nil {
		log.Println(err)
		return
	}
	if err := ctx.Process(data, func(segment whisper.Segment) {
		log.Println(segment.Text)
	}, nil); err != nil {
		log.Println(err)
	}
}

Any idea ??

thepacketloss avatar Mar 22 '24 11:03 thepacketloss

Does this still happen with the current version? It should have been fixed in the latest ggml sync.

slaren avatar Mar 27 '24 21:03 slaren

Does this still happen with the current version? It should have been fixed in the latest ggml sync.

I tested 2 times with master branch again and now this panic still happens but it's first line changed from this :

GGML_ASSERT: ggml-cuda.cu:7730: ptr == (void *) (g_cuda_pool_addr[device] + g_cuda_pool_used[device])

to this :

GGML_ASSERT: ggml-cuda.cu:351: ptr == (void *) (pool_addr + pool_used)

thepacketloss avatar Mar 30 '24 10:03 thepacketloss

This shouldn't happen unless the same ggml_backend instance is being used in multiple threads simultaneously, which I believe that also implies that the same whisper_context is being used in multiple threads. In which case, that looks like a bug in the go bindings. @ggerganov is this expected?

slaren avatar Mar 30 '24 10:03 slaren

This seems like a problem in the Go bindings, otherwise there would have been more reports. However, I don't think I can help with locating the problem - the Go code seems OK to me and I can't see an obvious problem, though I'm far from expert

ggerganov avatar Apr 09 '24 15:04 ggerganov