public AllocationInfo(ICudaArray array, TimeSpan creationTime, StackFrame stackFrame) { NumElements = array.Size; ElementSize = array.TypeSize; TypeName = array.Type.Name; CreationTime = creationTime; DeletionTime = null; Class = stackFrame?.GetMethod()?.DeclaringType?.Name; Method = stackFrame?.GetMethod()?.Name; File = stackFrame?.GetFileName(); Line = stackFrame?.GetFileLineNumber(); }
/** <summary>Internal method, only for use by <see cref="CudaArray{T}.Dispose"/>.</summary> */ internal void LogArrayDispose(ICudaArray array) { AllocationInfo info; if (!_activeAllocations.TryGetValue(array, out info)) { // problem! (but probably not crash-worthy?) } else { info.DeletionTime = _lifetime.Elapsed; _activeAllocations.Remove(array); CurrentBytes -= info.NumBytes; } }
/** <summary>Internal method, only for use by <see cref="CudaArray{T}"/> constructor.</summary> */ internal void LogArrayCreate(ICudaArray array) { StackFrame frame = GetCallerFrame(new StackTrace(2, fNeedFileInfo: true)); AllocationInfo info = new AllocationInfo(array, _lifetime.Elapsed, frame); if (_activeAllocations.ContainsKey(array)) { // problem! (but probably not crash-worthy?) } else { _activeAllocations[array] = info; _allAllocations.Add(info); CurrentBytes += info.NumBytes; TotalBytes += info.NumBytes; MaxBytes = Math.Max(MaxBytes, CurrentBytes); } }