@@ -27,6 +27,62 @@ namespace ROCDL {
27
27
// / 5. Returns an empty string.
28
28
StringRef getROCMPath ();
29
29
30
+ // / Helper class for specifying the AMD GCN device libraries required for
31
+ // / compilation.
32
+ class AMDGCNLibraryList {
33
+ public:
34
+ typedef enum : uint32_t {
35
+ None = 0 ,
36
+ Ockl = 1 ,
37
+ Ocml = 2 ,
38
+ OpenCL = 4 ,
39
+ Hip = 8 ,
40
+ LastLib = Hip,
41
+ All = (LastLib << 1 ) - 1
42
+ } Library;
43
+
44
+ explicit AMDGCNLibraryList (uint32_t libs = All) : libList(All & libs) {}
45
+
46
+ // / Return a list with no libraries.
47
+ static AMDGCNLibraryList getEmpty () { return AMDGCNLibraryList (None); }
48
+
49
+ // / Return the libraries needed for compiling code with OpenCL calls.
50
+ static AMDGCNLibraryList getOpenCL () {
51
+ return AMDGCNLibraryList (Ockl | Ocml | OpenCL);
52
+ }
53
+
54
+ // / Returns true if the list is empty.
55
+ bool isEmpty () const { return libList == None; }
56
+
57
+ // / Adds a library to the list.
58
+ AMDGCNLibraryList addLibrary (Library lib) {
59
+ libList = libList | lib;
60
+ return *this ;
61
+ }
62
+
63
+ // / Adds all the libraries in `list` to the library list.
64
+ AMDGCNLibraryList addList (AMDGCNLibraryList list) {
65
+ libList = libList | list.libList ;
66
+ return *this ;
67
+ }
68
+
69
+ // / Removes a library from the list.
70
+ AMDGCNLibraryList removeLibrary (Library lib) {
71
+ libList = libList & ~lib;
72
+ return *this ;
73
+ }
74
+
75
+ // / Returns true if `lib` is in the list of libraries.
76
+ bool requiresLibrary (Library lib) const { return (libList & lib) == lib; }
77
+
78
+ // / Returns true if `libList` contains any of the libraries in `libs`.
79
+ bool requiresAnyOf (uint32_t libs) const { return (libList & libs) != None; }
80
+
81
+ private:
82
+ // / Library list.
83
+ uint32_t libList;
84
+ };
85
+
30
86
// / Base class for all ROCDL serializations from GPU modules into binary
31
87
// / strings. By default this class serializes into LLVM bitcode.
32
88
class SerializeGPUModuleBase : public LLVM ::ModuleToObject {
@@ -49,8 +105,8 @@ class SerializeGPUModuleBase : public LLVM::ModuleToObject {
49
105
// / Returns the bitcode files to be loaded.
50
106
ArrayRef<std::string> getFileList () const ;
51
107
52
- // / Appends standard ROCm device libraries like `ocml.bc`, `ockl.bc`, etc .
53
- LogicalResult appendStandardLibs ();
108
+ // / Appends standard ROCm device libraries to `fileList` .
109
+ LogicalResult appendStandardLibs (AMDGCNLibraryList libs );
54
110
55
111
// / Loads the bitcode files in `fileList`.
56
112
virtual std::optional<SmallVector<std::unique_ptr<llvm::Module>>>
@@ -63,15 +119,20 @@ class SerializeGPUModuleBase : public LLVM::ModuleToObject {
63
119
LogicalResult handleBitcodeFile (llvm::Module &module ) override ;
64
120
65
121
protected:
66
- // / Appends the paths of common ROCm device libraries to `libs`.
67
- LogicalResult getCommonBitcodeLibs (llvm::SmallVector<std::string> &libs,
68
- SmallVector<char , 256 > &libPath,
69
- StringRef isaVersion);
70
-
71
122
// / Adds `oclc` control variables to the LLVM module.
72
- void addControlVariables (llvm::Module &module , bool wave64, bool daz,
73
- bool finiteOnly, bool unsafeMath, bool fastMath,
74
- bool correctSqrt, StringRef abiVer);
123
+ void addControlVariables (llvm::Module &module , AMDGCNLibraryList libs,
124
+ bool wave64, bool daz, bool finiteOnly,
125
+ bool unsafeMath, bool fastMath, bool correctSqrt,
126
+ StringRef abiVer);
127
+
128
+ // / Compiles assembly to a binary.
129
+ virtual std::optional<SmallVector<char , 0 >>
130
+ compileToBinary (const std::string &serializedISA);
131
+
132
+ // / Default implementation of `ModuleToObject::moduleToObject`.
133
+ std::optional<SmallVector<char , 0 >>
134
+ moduleToObjectImpl (const gpu::TargetOptions &targetOptions,
135
+ llvm::Module &llvmModule);
75
136
76
137
// / Returns the assembled ISA.
77
138
std::optional<SmallVector<char , 0 >> assembleIsa (StringRef isa);
@@ -84,6 +145,9 @@ class SerializeGPUModuleBase : public LLVM::ModuleToObject {
84
145
85
146
// / List of LLVM bitcode files to link to.
86
147
SmallVector<std::string> fileList;
148
+
149
+ // / AMD GCN libraries to use when linking, the default is using all.
150
+ AMDGCNLibraryList deviceLibs = AMDGCNLibraryList::getEmpty();
87
151
};
88
152
} // namespace ROCDL
89
153
} // namespace mlir
0 commit comments