Fix concurrency bug in generating tensor name
TensorCount should be wrapped by lock - Tensor name came from {PREFIX}_{CURRENT_TENSOR_COUNT} - atomic Addint64 is good but generating name from this is quite bug prone
This commit is contained in:
parent
e0fce090d5
commit
0e95225655
|
@ -65,6 +65,7 @@ func newTensor(ctensor lib.Ctensor, nameOpt ...string) *Tensor {
|
||||||
x.ctensor = ctensor
|
x.ctensor = ctensor
|
||||||
x.d = new(bigStruct)
|
x.d = new(bigStruct)
|
||||||
|
|
||||||
|
lock.Lock()
|
||||||
atomic.AddInt64(&TensorCount, 1)
|
atomic.AddInt64(&TensorCount, 1)
|
||||||
if gotch.Debug {
|
if gotch.Debug {
|
||||||
nbytes := x.nbytes()
|
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)
|
log.Printf("INFO: Added tensor %q - Allocated memory: %d bytes.\n", x.name, nbytes)
|
||||||
}
|
}
|
||||||
lock.Lock()
|
|
||||||
name := newName(nameOpt...)
|
name := newName(nameOpt...)
|
||||||
if _, ok := ExistingTensors[name]; ok {
|
if _, ok := ExistingTensors[name]; ok {
|
||||||
name = fmt.Sprintf("%s_%09d", name, TensorCount)
|
name = fmt.Sprintf("%s_%09d", name, TensorCount)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user