GCC Code Coverage Report


Directory: avs_core/
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 85.7% 12 / 0 / 14
Functions: 80.0% 4 / 0 / 5
Branches: -% 0 / 0 / 0

core/DeviceManager.h
Line Branch Exec Source
1 #pragma once
2
3 #include <avisynth.h>
4 #include <vector>
5 #include <atomic>
6 #include <memory>
7
8 class InternalEnvironment;
9 enum DeviceOpt: int; // forward enum w/o underlying types are MS specific
10
11 struct DeviceCompleteCallbackData {
12 void(*cb)(void*);
13 void* user_data;
14 };
15
16 class Device {
17 protected:
18 InternalEnvironment* env;
19
20 public:
21 const AvsDeviceType device_type;
22 const int device_id;
23 const int device_index;
24
25 uint64_t memory_max;
26 std::atomic<uint64_t> memory_used;
27
28 int free_thresh;
29
30 453 Device(AvsDeviceType type, int id, int index, InternalEnvironment* env) :
31 453 env(env),
32 453 device_type(type),
33 453 device_id(id),
34 453 device_index(index),
35 453 memory_max(0),
36 453 memory_used(0),
37 453 free_thresh(0)
38 453 { }
39
40 453 virtual ~Device() { }
41
42 virtual int SetMemoryMax(int mem) = 0;
43 virtual BYTE* Allocate(size_t sz, int margin) = 0;
44 virtual void Free(BYTE* ptr) = 0;
45 virtual const char* GetName() const = 0;
46 virtual void AddCompleteCallback(DeviceCompleteCallbackData cbdata) = 0;
47 virtual std::unique_ptr<std::vector<DeviceCompleteCallbackData>> GetAndClearCallbacks() = 0;
48 virtual void SetActiveToCurrentThread(InternalEnvironment* env) = 0;
49 virtual void* GetComputeStream() = 0;
50 virtual void SetDeviceOpt(DeviceOpt opt, int val, InternalEnvironment* env) = 0;
51 virtual void GetAlignmentRequirement(int* memoryAlignment, int* pitchAlignment) = 0;
52 };
53
54 class DeviceManager {
55 private:
56 InternalEnvironment *env;
57 std::unique_ptr<Device> cpuDevice;
58 std::vector<std::unique_ptr<Device>> cudaDevices;
59 int numDevices;
60
61 public:
62 DeviceManager(InternalEnvironment* env);
63 453 ~DeviceManager() { }
64
65 Device* GetDevice(AvsDeviceType device_type, int device_index) const;
66
67 961 Device* GetCPUDevice() { return GetDevice(DEV_TYPE_CPU, 0); }
68
69 int GetNumDevices() const { return numDevices; }
70 int GetNumDevices(AvsDeviceType device_type) const;
71
72 void SetDeviceOpt(DeviceOpt opt, int val, InternalEnvironment* env);
73 };
74
75 class DeviceSetter {
76 InternalEnvironment* env;
77 Device* downstreamDevice;
78 public:
79 DeviceSetter(InternalEnvironment* env, Device* upstreamDevice);
80 ~DeviceSetter();
81 };
82
83 void CheckChildDeviceTypes(const PClip& child, const char* name, const AVSValue& last,
84 const AVSValue& args, const char* const* argnames, InternalEnvironment* env);
85
86 void CopyCUDAFrame(const PVideoFrame& dst, const PVideoFrame& src, InternalEnvironment* env, bool sync = false);
87