newDeviceAllocator returns a new device allocator instances.
()
| 156 | |
| 157 | // newDeviceAllocator returns a new device allocator instances. |
| 158 | func newDeviceAllocator() deviceAllocator { |
| 159 | var da deviceAllocator |
| 160 | deviceCount := cgoutils.GetDeviceCount() |
| 161 | if cgoutils.IsPooledMemory() { |
| 162 | utils.GetLogger().Info("Using pooled device memory manager") |
| 163 | da = &pooledDeviceAllocatorImpl{} |
| 164 | } else { |
| 165 | utils.GetLogger().Info("Using memory tracking device memory manager") |
| 166 | da = &memoryTrackingDeviceAllocatorImpl{ |
| 167 | memoryUsage: make([]int64, deviceCount), |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | // Start memory usage reporting go routine. |
| 172 | // Report the allocated memory of each device per memoryReportingInterval. |
| 173 | timer := time.NewTimer(memoryReportingInterval) |
| 174 | go func() { |
| 175 | for { |
| 176 | select { |
| 177 | case <-timer.C: |
| 178 | reportAllocatedMemory(deviceCount, da) |
| 179 | // Since we already receive the event from channel, |
| 180 | // there is no need to stop it and we can directly reset the timer. |
| 181 | timer.Reset(memoryReportingInterval) |
| 182 | } |
| 183 | } |
| 184 | }() |
| 185 | return da |
| 186 | } |
| 187 | |
| 188 | // memoryTrackingDeviceAllocatorImpl maintains the memory space for each device and reports the updated memory every time an |
| 189 | // allocation/free request is issued. |
no test coverage detected