| 61 | } |
| 62 | |
| 63 | Kernel getKernel(const string& kernelName, span<const common::Source> sources, |
| 64 | span<const TemplateArg> targs, span<const string> options, |
| 65 | const bool sourceIsJIT) { |
| 66 | string tInstance = kernelName; |
| 67 | |
| 68 | #if defined(AF_CUDA) |
| 69 | auto targsIt = targs.begin(); |
| 70 | auto targsEnd = targs.end(); |
| 71 | if (targsIt != targsEnd) { |
| 72 | tInstance += '<' + targsIt->_tparam; |
| 73 | while (++targsIt != targsEnd) { tInstance += ',' + targsIt->_tparam; } |
| 74 | tInstance += '>'; |
| 75 | } |
| 76 | #else |
| 77 | UNUSED(targs); |
| 78 | #endif |
| 79 | |
| 80 | // The JIT kernel uses the hashing of the kernelName (tInstance) only to |
| 81 | // speed up to search for its cached kernel. All the other kernels have the |
| 82 | // full source code linked in, and will hash the full code + options |
| 83 | // instead. |
| 84 | size_t moduleKeyCache = 0; |
| 85 | if (sourceIsJIT) { |
| 86 | moduleKeyCache = deterministicHash(tInstance); |
| 87 | } else { |
| 88 | moduleKeyCache = (sources.size() == 1 && sources[0].hash) |
| 89 | ? sources[0].hash |
| 90 | : deterministicHash(sources); |
| 91 | moduleKeyCache = deterministicHash(options, moduleKeyCache); |
| 92 | #if defined(AF_CUDA) |
| 93 | moduleKeyCache = deterministicHash(tInstance, moduleKeyCache); |
| 94 | #endif |
| 95 | } |
| 96 | const int device = detail::getActiveDeviceId(); |
| 97 | Module currModule = findModule(device, moduleKeyCache); |
| 98 | |
| 99 | if (!currModule) { |
| 100 | // When saving on disk, the moduleKeyDisk has to correspond with the |
| 101 | // full code + optinos (in all circumstances). A recalculation for JIT |
| 102 | // is necessary, while for the others we can reuse the moduleKeyCache. |
| 103 | size_t moduleKeyDisk = 0; |
| 104 | if (sourceIsJIT) { |
| 105 | moduleKeyDisk = (sources.size() == 1 && sources[0].hash) |
| 106 | ? sources[0].hash |
| 107 | : deterministicHash(sources); |
| 108 | moduleKeyDisk = deterministicHash(options, moduleKeyDisk); |
| 109 | #if defined(AF_CUDA) |
| 110 | moduleKeyDisk = deterministicHash(tInstance, moduleKeyDisk); |
| 111 | #endif |
| 112 | } else { |
| 113 | moduleKeyDisk = moduleKeyCache; |
| 114 | } |
| 115 | currModule = |
| 116 | loadModuleFromDisk(device, to_string(moduleKeyDisk), sourceIsJIT); |
| 117 | if (!currModule) { |
| 118 | vector<string> sources_str; |
| 119 | for (const auto& s : sources) { |
| 120 | sources_str.push_back({s.ptr, s.length}); |
nothing calls this directly
no test coverage detected