This repository has been archived by the owner on Jan 13, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 50
Reuse temporary memory allocations #478
Merged
muhammad-tanvir-1211
merged 6 commits into
codeplaysoftware:master
from
pgorlani:sb_handle-temp-mem-pr
Jan 25, 2024
+521
−109
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5666d31
Store temporary memory allocations
pgorlani e188e71
Pass sb_handle as an argument to the auto tuners
pgorlani d7ef560
Delete copy constructor and assign operator
pgorlani 3ba8ad7
Add separate memory pool class
pgorlani 75a4aa0
add for iamax and iamin
pgorlani 9b4ca54
NULL -> nullptr
pgorlani File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,112 @@ | ||
/*************************************************************************** | ||
* | ||
* @license | ||
* Copyright (C) Codeplay Software Limited | ||
* 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 | ||
* | ||
* For your convenience, a copy of the License has been included in this | ||
* repository. | ||
* | ||
* 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. | ||
* | ||
* portBLAS: BLAS implementation using SYCL | ||
* | ||
* @filename temp_memory_pool.h | ||
* | ||
**************************************************************************/ | ||
#ifndef TEMP_MEMORY_POOL_H | ||
#define TEMP_MEMORY_POOL_H | ||
|
||
#include <map> | ||
#include <mutex> | ||
|
||
namespace blas { | ||
class Temp_Mem_Pool { | ||
using queue_t = cl::sycl::queue; | ||
using event_t = std::vector<cl::sycl::event>; | ||
using temp_usm_map_t = std::multimap<size_t, void*>; | ||
using temp_usm_size_map_t = std::map<void*, size_t>; | ||
using temp_buffer_map_t = std::multimap<size_t, cl::sycl::buffer<int8_t, 1>>; | ||
|
||
public: | ||
Temp_Mem_Pool(queue_t q) | ||
: q_(q), | ||
temp_buffer_map_tot_byte_size_(0), | ||
temp_usm_map_tot_byte_size_(0) {} | ||
Temp_Mem_Pool(const Temp_Mem_Pool& h) = delete; | ||
Temp_Mem_Pool operator=(Temp_Mem_Pool) = delete; | ||
|
||
~Temp_Mem_Pool() { | ||
// Wait for the completion of all the host tasks | ||
q_.wait(); | ||
|
||
#ifdef VERBOSE | ||
std::cout << "# buffers destroyed on memory pool destruction: " | ||
<< temp_buffer_map_.size() << " (" | ||
<< temp_buffer_map_tot_byte_size_ << " bytes)" << std::endl; | ||
#endif | ||
|
||
#ifdef SB_ENABLE_USM | ||
#ifdef VERBOSE | ||
std::cout << "# USM allocations freed on memory pool destruction: " | ||
<< temp_usm_map_.size() << " (" << temp_usm_map_tot_byte_size_ | ||
<< " bytes)" << std::endl; | ||
#endif | ||
for (const temp_usm_map_t::value_type& p : temp_usm_map_) | ||
cl::sycl::free(p.second, q_); | ||
#endif | ||
} | ||
|
||
inline queue_t get_queue() const { return q_; } | ||
|
||
template <typename value_t> | ||
typename helper::AllocHelper<value_t, helper::AllocType::buffer>::type | ||
acquire_buff_mem(size_t size); | ||
|
||
template <typename container_t> | ||
typename Temp_Mem_Pool::event_t release_buff_mem( | ||
const typename Temp_Mem_Pool::event_t&, const container_t&); | ||
|
||
#ifdef SB_ENABLE_USM | ||
template <typename value_t> | ||
typename helper::AllocHelper<value_t, helper::AllocType::usm>::type | ||
acquire_usm_mem(size_t size); | ||
|
||
template <typename container_t> | ||
typename Temp_Mem_Pool::event_t release_usm_mem( | ||
const typename Temp_Mem_Pool::event_t&, const container_t&); | ||
#endif | ||
|
||
private: | ||
static_assert(sizeof(temp_buffer_map_t::mapped_type::value_type) == 1); | ||
|
||
static constexpr size_t max_size_temp_mem_ = 1e9; | ||
s-Nick marked this conversation as resolved.
Show resolved
Hide resolved
|
||
queue_t q_; | ||
|
||
std::mutex temp_buffer_map_mutex_; | ||
size_t temp_buffer_map_tot_byte_size_; | ||
temp_buffer_map_t temp_buffer_map_; | ||
|
||
template <typename container_t> | ||
void release_usm_mem_(const container_t& mem); | ||
|
||
#ifdef SB_ENABLE_USM | ||
std::mutex temp_usm_map_mutex_; | ||
size_t temp_usm_map_tot_byte_size_; | ||
temp_usm_map_t temp_usm_map_; | ||
temp_usm_size_map_t temp_usm_size_map_; | ||
|
||
template <typename container_t> | ||
void release_buff_mem_(const container_t& mem); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry for the late comment. I think this one should be swapped with the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in aa1fdf1. |
||
#endif | ||
}; | ||
} // namespace blas | ||
#endif |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the
temp_usm_map_tot_byte_size_
is undefined if SB_ENABLE_USM is not defined.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in aa1fdf1.