-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Minor fixes on the file permission, host allocation flag, and worker …
…thread initialization (#637) This PR makes the following minor fixes: - Use the correct file permission flags corresponding to the `644` code. - Use the correct flag for the `cuMemHostAlloc` call. - For the thread pool, replace the `thread_local` call-once section (which may negatively affect performance; see #630 (comment)) with more idiomatic worker thread initialization function. Authors: - Tianyu Liu (https://github.com/kingcrimsontianyu) Approvers: - Mads R. B. Kristensen (https://github.com/madsbk) - Vukasin Milovanovic (https://github.com/vuule) URL: #637
- Loading branch information
1 parent
a9bc84c
commit 08ab53b
Showing
9 changed files
with
83 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright (c) 2025, NVIDIA CORPORATION. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <functional> | ||
|
||
#include <BS_thread_pool.hpp> | ||
|
||
#include <kvikio/nvtx.hpp> | ||
|
||
namespace kvikio { | ||
|
||
template <typename pool_type> | ||
class thread_pool_wrapper : public pool_type { | ||
public: | ||
/** | ||
* @brief Construct a new thread pool wrapper, and invoke a pre-defined initialization function in | ||
* each worker thread. | ||
* | ||
* @param nthreads The number of threads to use. | ||
*/ | ||
thread_pool_wrapper(unsigned int nthreads) : pool_type{nthreads, worker_thread_init_func} {} | ||
|
||
/** | ||
* @brief Reset the number of threads in the thread pool, and invoke a pre-defined initialization | ||
* function in each worker thread. | ||
* | ||
* @param nthreads The number of threads to use. | ||
*/ | ||
void reset(unsigned int nthreads) { pool_type::reset(nthreads, worker_thread_init_func); } | ||
|
||
private: | ||
inline static std::function<void()> worker_thread_init_func{[] { | ||
KVIKIO_NVTX_SCOPED_RANGE("worker thread init", 0, NvtxManager::default_color()); | ||
// Rename the worker thread in the thread pool to improve clarity from nsys-ui. | ||
// Note: This NVTX feature is currently not supported by nsys-ui. | ||
NvtxManager::rename_current_thread("thread pool"); | ||
}}; | ||
}; | ||
|
||
using BS_thread_pool = thread_pool_wrapper<BS::thread_pool>; | ||
|
||
} // namespace kvikio |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters