-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathAlgorithmLauncher.cpp
More file actions
65 lines (55 loc) · 1.92 KB
/
Copy pathAlgorithmLauncher.cpp
File metadata and controls
65 lines (55 loc) · 1.92 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
62
63
64
65
/*
* SPDX-FileCopyrightText: Copyright (c) 2025-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/
#include <AlgorithmLauncher.hpp>
#include <raft/util/cuda_rt_essentials.hpp>
AlgorithmLauncher::AlgorithmLauncher(cudaKernel_t k, cudaLibrary_t lib) : kernel{k}, library{lib} {}
AlgorithmLauncher::~AlgorithmLauncher()
{
if (library != nullptr) { (void)cudaLibraryUnload(library); }
}
AlgorithmLauncher::AlgorithmLauncher(AlgorithmLauncher&& other) noexcept
: kernel{other.kernel}, library{other.library}
{
other.kernel = nullptr;
other.library = nullptr;
}
AlgorithmLauncher& AlgorithmLauncher::operator=(AlgorithmLauncher&& other) noexcept
{
if (this != &other) {
if (library != nullptr) { cudaLibraryUnload(library); }
kernel = other.kernel;
library = other.library;
other.kernel = nullptr;
other.library = nullptr;
}
return *this;
}
void AlgorithmLauncher::call(
cudaStream_t stream, dim3 grid, dim3 block, std::size_t shared_mem, void** kernel_args)
{
cudaLaunchConfig_t config{};
config.gridDim = grid;
config.blockDim = block;
config.stream = stream;
config.dynamicSmemBytes = shared_mem;
config.numAttrs = 0;
config.attrs = NULL;
RAFT_CUDA_TRY(cudaLaunchKernelExC(&config, kernel, kernel_args));
}
void AlgorithmLauncher::call_cooperative(
cudaStream_t stream, dim3 grid, dim3 block, std::size_t shared_mem, void** kernel_args)
{
cudaLaunchAttribute attribute[1];
attribute[0].id = cudaLaunchAttributeCooperative;
attribute[0].val.cooperative = 1;
cudaLaunchConfig_t config{};
config.gridDim = grid;
config.blockDim = block;
config.stream = stream;
config.dynamicSmemBytes = shared_mem;
config.numAttrs = 1;
config.attrs = attribute;
RAFT_CUDA_TRY(cudaLaunchKernelExC(&config, kernel, kernel_args));
}