Talvos  0.1
SPIR-V interpreter and dynamic analysis framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Workgroup.cpp
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 #include <spirv/unified1/spirv.h>
10 
11 #include "PipelineExecutor.h"
12 #include "talvos/Invocation.h"
13 #include "talvos/Memory.h"
14 #include "talvos/Module.h"
15 #include "talvos/PipelineStage.h"
16 #include "talvos/Type.h"
17 #include "talvos/Variable.h"
18 #include "talvos/Workgroup.h"
19 
20 namespace talvos
21 {
22 
24  Dim3 GroupId)
25 {
26  this->GroupId = GroupId;
28 
29  const PipelineStage &Stage = Executor.getCurrentStage();
30 
31  // Allocate workgroup variables.
32  for (auto V : Stage.getModule()->getVariables())
33  {
34  const Type *Ty = V->getType();
35  if (Ty->getStorageClass() != SpvStorageClassWorkgroup)
36  continue;
37 
38  size_t NumBytes = Ty->getElementType()->getSize();
39  uint64_t Address = LocalMemory->allocate(NumBytes);
40  Variables.push_back({V->getId(), Object(Ty, Address)});
41  }
42 }
43 
45 
46 void Workgroup::addWorkItem(std::unique_ptr<Invocation> WorkItem)
47 {
48  WorkItems.push_back(std::move(WorkItem));
49 }
50 
51 } // namespace talvos
This file declares the Workgroup class.
size_t getSize() const
Returns the size of this type in bytes.
Definition: Type.h:81
This file declares the Module class.
const Type * getElementType(uint64_t Index=0) const
Returns the type of the element at Index.
Definition: Type.cpp:38
std::shared_ptr< const Module > getModule() const
Return the module this pipeline stage is using.
Definition: PipelineStage.h:57
Dim3 GroupId
The group ID.
Definition: Workgroup.h:64
void addWorkItem(std::unique_ptr< Invocation > WorkItem)
Add a work-item invocation to this group, transferring ownership.
Definition: Workgroup.cpp:46
const PipelineStage & getCurrentStage() const
Returns the pipeline stage that is currently being executed.
WorkItemList WorkItems
List of work items in this workgroup.
Definition: Workgroup.h:68
VariableList Variables
Workgroup scope OpVariable allocations.
Definition: Workgroup.h:70
This file declares the Type class.
Class representing a 3-dimensional size or ID.
Definition: Dim3.h:22
This file declares the PipelineExecutor class.
Workgroup(Device &Dev, const PipelineExecutor &Executor, Dim3 GroupId)
Create a workgroup.
Definition: Workgroup.cpp:23
This class represents an address space in the virtual device.
Definition: Memory.h:37
This file declares the PipelineStage class.
An internal class that handles pipeline execution, including the interactive debugger.
uint32_t getStorageClass() const
Returns the storage class of this type.
Definition: Type.cpp:60
A Device instance encapsulates properties and state for the virtual device.
Definition: Device.h:29
This class encapsulates information about a pipeline stage.
Definition: PipelineStage.h:30
This file declares the Memory class.
Memory * LocalMemory
The local memory of this workgroup.
Definition: Workgroup.h:66
~Workgroup()
Destroy this workgroup.
Definition: Workgroup.cpp:44
This class represents a SPIR-V type.
Definition: Type.h:33
This file declares the Invocation class.
uint64_t allocate(uint64_t NumBytes)
Allocate a new buffer of size NumBytes.
Definition: Memory.cpp:52
This class represents an instruction result.
Definition: Object.h:51
This file declares the Variable class.