Merge pull request #113 from pjongy/fix_concurrency_bug

Fix concurrency bug in generating tensor name
This commit is contained in:
sugarme 2023-10-24 14:06:49 +11:00 committed by GitHub
commit 05eb7f538b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -65,6 +65,7 @@ func newTensor(ctensor lib.Ctensor, nameOpt ...string) *Tensor {
x.ctensor = ctensor
x.d = new(bigStruct)
lock.Lock()
atomic.AddInt64(&TensorCount, 1)
if gotch.Debug {
nbytes := x.nbytes()
@ -72,7 +73,6 @@ func newTensor(ctensor lib.Ctensor, nameOpt ...string) *Tensor {
log.Printf("INFO: Added tensor %q - Allocated memory: %d bytes.\n", x.name, nbytes)
}
lock.Lock()
name := newName(nameOpt...)
if _, ok := ExistingTensors[name]; ok {
name = fmt.Sprintf("%s_%09d", name, TensorCount)