Fix concurrency issue in newTensor
This commit is contained in:
parent
cd0565716f
commit
7533f43c2e
|
@ -60,7 +60,6 @@ func newTensor(ctensor lib.Ctensor, nameOpt ...string) *Tensor {
|
||||||
if len(nameOpt) == 0 {
|
if len(nameOpt) == 0 {
|
||||||
nameOpt = []string{}
|
nameOpt = []string{}
|
||||||
}
|
}
|
||||||
name := newName(nameOpt...)
|
|
||||||
|
|
||||||
x := new(Tensor)
|
x := new(Tensor)
|
||||||
x.ctensor = ctensor
|
x.ctensor = ctensor
|
||||||
|
@ -70,6 +69,7 @@ func newTensor(ctensor lib.Ctensor, nameOpt ...string) *Tensor {
|
||||||
nbytes := x.nbytes()
|
nbytes := x.nbytes()
|
||||||
atomic.AddInt64(&AllocatedMem, nbytes)
|
atomic.AddInt64(&AllocatedMem, nbytes)
|
||||||
lock.Lock()
|
lock.Lock()
|
||||||
|
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