Talvos  0.1
SPIR-V interpreter and dynamic analysis framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Device.h
Go to the documentation of this file.
1 // Copyright (c) 2018 the Talvos developers. All rights reserved.
2 //
3 // This file is distributed under a three-clause BSD license. For full license
4 // terms please see the LICENSE file distributed with this source code.
5 
8 
9 #ifndef TALVOS_DEVICE_H
10 #define TALVOS_DEVICE_H
11 
12 #include <condition_variable>
13 #include <memory>
14 #include <mutex>
15 #include <vector>
16 
17 namespace talvos
18 {
19 
20 class Command;
21 class Instruction;
22 class Invocation;
23 class Memory;
24 class PipelineExecutor;
25 class Plugin;
26 class Workgroup;
27 
29 class Device
30 {
31 public:
32  Device();
33  ~Device();
34 
35  // Do not allow Device objects to be copied.
37  Device(const Device &) = delete;
38  Device &operator=(const Device &) = delete;
40 
43 
46 
48  bool isThreadSafe() const;
49 
51  void notifyFenceSignaled();
52 
56  void reportError(const std::string &Error, bool Fatal = false);
57 
60  void reportAtomicAccess(const Memory *Mem, uint64_t Address,
61  uint64_t NumBytes, uint32_t Opcode, uint32_t Scope,
62  uint32_t Semantics);
63  void reportCommandBegin(const Command *Cmd);
64  void reportCommandComplete(const Command *Cmd);
65  void reportInstructionExecuted(const Invocation *Invoc,
66  const Instruction *Inst);
67  void reportInvocationBegin(const Invocation *Invoc);
68  void reportInvocationComplete(const Invocation *Invoc);
69  void reportMemoryLoad(const Memory *Mem, uint64_t Address, uint64_t NumBytes);
70  void reportMemoryMap(const Memory *Mem, uint64_t Base, uint64_t Offset,
71  uint64_t NumBytes);
72  void reportMemoryStore(const Memory *Mem, uint64_t Address, uint64_t NumBytes,
73  const uint8_t *Data);
74  void reportMemoryUnmap(const Memory *Mem, uint64_t Base);
75  void reportWorkgroupBegin(const Workgroup *Group);
76  void reportWorkgroupBarrier(const Workgroup *Group);
77  void reportWorkgroupComplete(const Workgroup *Group);
79 
85  bool waitForFences(const std::vector<const bool *> &Fences, bool WaitAll,
86  uint64_t Timeout) const;
87 
88 private:
90 
92  std::vector<std::pair<void *, Plugin *>> Plugins;
93 
96 
98  size_t MaxErrors;
99 
101  mutable std::mutex FenceMutex;
102 
104  mutable std::condition_variable FenceSignaled;
105 };
106 
107 } // namespace talvos
108 
109 #endif
void reportError(const std::string &Error, bool Fatal=false)
Report an error that has occurred during emulation.
Definition: Device.cpp:146
void notifyFenceSignaled()
Notify the device that a fence was signaled.
Definition: Device.cpp:140
std::vector< std::pair< void *, Plugin * > > Plugins
List of plugins that are currently loaded.
Definition: Device.h:92
void reportMemoryMap(const Memory *Mem, uint64_t Base, uint64_t Offset, uint64_t NumBytes)
Definition: Device.cpp:285
void reportInvocationComplete(const Invocation *Invoc)
Definition: Device.cpp:264
void reportWorkgroupComplete(const Workgroup *Group)
Definition: Device.cpp:322
std::condition_variable FenceSignaled
Condition variable to notify threads waiting on fence signals.
Definition: Device.h:104
This class is a base class for all commands.
Definition: Commands.h:31
This class represents a single execution of a SPIR-V entry point.
Definition: Invocation.h:33
PipelineExecutor * Executor
The pipeline executor instance.
Definition: Device.h:95
Memory * GlobalMemory
The global memory of this device.
Definition: Device.h:89
size_t MaxErrors
The maximum number of errors to report.
Definition: Device.h:98
void reportCommandBegin(const Command *Cmd)
Definition: Device.cpp:243
This class represents an address space in the virtual device.
Definition: Memory.h:37
An internal class that handles pipeline execution, including the interactive debugger.
bool waitForFences(const std::vector< const bool * > &Fences, bool WaitAll, uint64_t Timeout) const
Wait for fences to signal.
Definition: Device.cpp:329
void reportWorkgroupBarrier(const Workgroup *Group)
Definition: Device.cpp:317
std::mutex FenceMutex
A mutex for synchronizing threads waiting on fence signals.
Definition: Device.h:101
A Device instance encapsulates properties and state for the virtual device.
Definition: Device.h:29
This class represents a workgroup executing a compute command.
Definition: Workgroup.h:27
void reportInvocationBegin(const Invocation *Invoc)
Definition: Device.cpp:259
void reportMemoryStore(const Memory *Mem, uint64_t Address, uint64_t NumBytes, const uint8_t *Data)
Definition: Device.cpp:291
PipelineExecutor & getPipelineExecutor()
Returns the PipelineExecutor for this device.
Definition: Device.h:45
Memory & getGlobalMemory()
Get the global memory instance associated with this device.
Definition: Device.h:42
void reportAtomicAccess(const Memory *Mem, uint64_t Address, uint64_t NumBytes, uint32_t Opcode, uint32_t Scope, uint32_t Semantics)
Definition: Device.cpp:234
bool isThreadSafe() const
Returns true if all of the loaded plugins are thread-safe.
Definition: Device.cpp:132
Device & operator=(const Device &)=delete
void reportCommandComplete(const Command *Cmd)
Definition: Device.cpp:248
void reportMemoryLoad(const Memory *Mem, uint64_t Address, uint64_t NumBytes)
Definition: Device.cpp:269
This class represents a SPIR-V instruction.
Definition: Instruction.h:27
void reportWorkgroupBegin(const Workgroup *Group)
Definition: Device.cpp:312
void reportMemoryUnmap(const Memory *Mem, uint64_t Base)
Definition: Device.cpp:307
void reportInstructionExecuted(const Invocation *Invoc, const Instruction *Inst)
Definition: Device.cpp:253