Mneme
Mneme a tool allowing recording the execution of a GPU (CUDA/HIP) kernel and replaying that kernel as an independent executable.
Loading...
Searching...
No Matches
MnemeKernelInfo.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <llvm/ADT/DenseMap.h>
4#include <llvm/ADT/SmallVector.h>
5#include <llvm/ADT/StringRef.h>
6#include <llvm/ADT/ArrayRef.h>
7#include <llvm/ADT/DenseMap.h>
8#include <llvm/ADT/SmallVector.h>
9#include <llvm/ADT/StableHashing.h>
10#include <llvm/Support/raw_ostream.h>
11
12namespace mneme {
13struct KernelInfo {
14 const void *HostFun;
15 std::string Name;
16 std::optional<uint64_t> StaticHash;
17 llvm::SmallVector<size_t> KernelArgSizes;
18 llvm::SmallVector<std::string> KernelArgNames;
19 llvm::SmallVector<std::function<double(void *)>> ToDoubleFunc;
20 llvm::SmallVector<bool> KernelSpecializations;
21 llvm::SmallVector<std::unique_ptr<uint8_t[]>> ArgData;
22 KernelInfo(const void *HostFun, const char *Name)
23 : HostFun(HostFun), Name(Name), StaticHash(std::nullopt) {};
24 KernelInfo(const std::string &Name) : Name(Name), StaticHash(std::nullopt) {};
25
26public:
27 void setArgSizes(llvm::ArrayRef<size_t> ArgSizes) {
28 KernelArgSizes = llvm::SmallVector<size_t>(ArgSizes);
29 }
30
31 void setArgNames(llvm::ArrayRef<std::string> Names) {
32 KernelArgNames = llvm::SmallVector<std::string>(Names);
33 }
34
35 void setSpecializations(llvm::ArrayRef<bool> Specializations) {
36 KernelSpecializations = llvm::SmallVector<bool>(Specializations);
37 }
38
39 void setArgData(const char *&Data, int Index) {
40 if (Index >= KernelArgSizes.size() || Index >= ArgData.size())
41 LOG_FATAL("Setting argument data out of range");
42
43 auto MemSize = KernelArgSizes[Index];
44 ArgData[Index] = std::make_unique<uint8_t[]>(MemSize);
45 std::memcpy(static_cast<void *>(ArgData[Index].get()),
46 static_cast<const void *>(Data), MemSize);
47 Data += KernelArgSizes[Index];
48 }
49
50 void setToDoubleFunc(llvm::ArrayRef<std::function<double(void *)>> convert) {
51 ToDoubleFunc = llvm::SmallVector<std::function<double(void *)>>(convert);
52 }
53
54 int64_t getNumArgs() const { return KernelArgSizes.size(); }
55 const std::string getName() const { return Name; }
56 const void *getFunHandle() const { return HostFun; }
57 llvm::ArrayRef<size_t> getArgSizes() const { return KernelArgSizes; }
58 llvm::ArrayRef<std::string> getArgNames() const { return KernelArgNames; }
59 llvm::ArrayRef<bool> getArgSpecializations() const {
61 }
62
63 llvm::ArrayRef<std::unique_ptr<uint8_t[]>> getArgData() const {
64 return ArgData;
65 }
66
67 llvm::ArrayRef<std::function<double(void *)>> getToDoubleFunc() const {
68 return ToDoubleFunc;
69 }
70};
71} // namespace mneme
#define LOG_FATAL(...)
Definition MnemeLogger.hpp:113
Definition MnemeAnnotation.cpp:3
llvm::ArrayRef< std::string > getArgNames() const
Definition MnemeKernelInfo.hpp:58
llvm::ArrayRef< size_t > getArgSizes() const
Definition MnemeKernelInfo.hpp:57
void setArgSizes(llvm::ArrayRef< size_t > ArgSizes)
Definition MnemeKernelInfo.hpp:27
llvm::ArrayRef< std::function< double(void *)> > getToDoubleFunc() const
Definition MnemeKernelInfo.hpp:67
llvm::SmallVector< std::string > KernelArgNames
Definition MnemeKernelInfo.hpp:18
KernelInfo(const std::string &Name)
Definition MnemeKernelInfo.hpp:24
int64_t getNumArgs() const
Definition MnemeKernelInfo.hpp:54
llvm::SmallVector< bool > KernelSpecializations
Definition MnemeKernelInfo.hpp:20
void setSpecializations(llvm::ArrayRef< bool > Specializations)
Definition MnemeKernelInfo.hpp:35
const void * HostFun
Definition MnemeKernelInfo.hpp:14
void setArgNames(llvm::ArrayRef< std::string > Names)
Definition MnemeKernelInfo.hpp:31
void setArgData(const char *&Data, int Index)
Definition MnemeKernelInfo.hpp:39
std::string Name
Definition MnemeKernelInfo.hpp:15
std::optional< uint64_t > StaticHash
Definition MnemeKernelInfo.hpp:16
llvm::ArrayRef< std::unique_ptr< uint8_t[]> > getArgData() const
Definition MnemeKernelInfo.hpp:63
const std::string getName() const
Definition MnemeKernelInfo.hpp:55
void setToDoubleFunc(llvm::ArrayRef< std::function< double(void *)> > convert)
Definition MnemeKernelInfo.hpp:50
KernelInfo(const void *HostFun, const char *Name)
Definition MnemeKernelInfo.hpp:22
llvm::SmallVector< size_t > KernelArgSizes
Definition MnemeKernelInfo.hpp:17
llvm::ArrayRef< bool > getArgSpecializations() const
Definition MnemeKernelInfo.hpp:59
const void * getFunHandle() const
Definition MnemeKernelInfo.hpp:56
llvm::SmallVector< std::unique_ptr< uint8_t[]> > ArgData
Definition MnemeKernelInfo.hpp:21
llvm::SmallVector< std::function< double(void *)> > ToDoubleFunc
Definition MnemeKernelInfo.hpp:19