-
Notifications
You must be signed in to change notification settings - Fork 548
Expand file tree
/
Copy pathModule.hpp
More file actions
61 lines (47 loc) · 1.59 KB
/
Module.hpp
File metadata and controls
61 lines (47 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*******************************************************
* Copyright (c) 2020, ArrayFire
* All rights reserved.
*
* This file is distributed under 3-clause BSD license.
* The complete license agreement can be obtained at:
* http://arrayfire.com/licenses/BSD-3-Clause
********************************************************/
#pragma once
#include <common/ModuleInterface.hpp>
#include <err_cuda.hpp>
#include <cuda.h>
#include <string>
#include <unordered_map>
namespace arrayfire {
namespace cuda {
/// CUDA backend wrapper for CUmodule
class Module : public common::ModuleInterface<CUmodule> {
private:
std::unordered_map<std::string, std::string> mInstanceMangledNames;
public:
using ModuleType = CUmodule;
using BaseClass = common::ModuleInterface<ModuleType>;
Module() = default;
Module(ModuleType mod) : BaseClass(mod) {
mInstanceMangledNames.reserve(1);
}
operator bool() const final { return get(); }
void unload() final {
CU_CHECK(cuModuleUnload(get()));
set(nullptr);
}
const std::string mangledName(const std::string& instantiation) const {
auto iter = mInstanceMangledNames.find(instantiation);
if (iter != mInstanceMangledNames.end()) {
return iter->second;
} else {
return std::string("");
}
}
void add(const std::string& instantiation, const std::string& mangledName) {
mInstanceMangledNames.emplace(instantiation, mangledName);
}
const auto& map() const { return mInstanceMangledNames; }
};
} // namespace cuda
} // namespace arrayfire