diff --git a/projects/rocprofiler-sdk/source/lib/common/CMakeLists.txt b/projects/rocprofiler-sdk/source/lib/common/CMakeLists.txt index d720fefb1b..84139c3190 100644 --- a/projects/rocprofiler-sdk/source/lib/common/CMakeLists.txt +++ b/projects/rocprofiler-sdk/source/lib/common/CMakeLists.txt @@ -2,7 +2,8 @@ # Builds common utilities into a static library # set(common_sources config.cpp environment.cpp demangle.cpp) -set(common_headers config.hpp defines.hpp environment.hpp demangle.hpp mpl.hpp) +set(common_headers config.hpp defines.hpp environment.hpp demangle.hpp mpl.hpp + utility.hpp) add_library(rocprofiler-common-library STATIC) add_library(rocprofiler::rocprofiler-common-library ALIAS rocprofiler-common-library) diff --git a/projects/rocprofiler-sdk/source/lib/common/container/operators.hpp b/projects/rocprofiler-sdk/source/lib/common/container/operators.hpp index bf184b7b71..3531fd9fd5 100644 --- a/projects/rocprofiler-sdk/source/lib/common/container/operators.hpp +++ b/projects/rocprofiler-sdk/source/lib/common/container/operators.hpp @@ -33,9 +33,9 @@ #define ROCPROFILER_OPERATOR_TEMPLATE2(template_name2) \ ROCPROFILER_IMPORT_TEMPLATE2(template_name2) \ template \ - struct is_chained_base<::rocprofiler::container::template_name2> \ + struct is_chained_base<::rocprofiler::common::container::template_name2> \ { \ - using value = ::rocprofiler::container::true_t; \ + using value = ::rocprofiler::common::container::true_t; \ }; // Import a 1-type-argument operator template into boost (if necessary) and @@ -43,9 +43,9 @@ #define ROCPROFILER_OPERATOR_TEMPLATE1(template_name1) \ ROCPROFILER_IMPORT_TEMPLATE1(template_name1) \ template \ - struct is_chained_base<::rocprofiler::container::template_name1> \ + struct is_chained_base<::rocprofiler::common::container::template_name1> \ { \ - using value = ::rocprofiler::container::true_t; \ + using value = ::rocprofiler::common::container::true_t; \ }; #define ROCPROFILER_OPERATOR_TEMPLATE(template_name) \ @@ -74,7 +74,7 @@ template \ struct is_chained_base> \ { \ - using value = ::rocprofiler::container::true_t; \ + using value = ::rocprofiler::common::container::true_t; \ }; \ \ ROCPROFILER_OPERATOR_TEMPLATE2(template_name##2) \ diff --git a/projects/rocprofiler-sdk/source/lib/common/container/stable_vector.hpp b/projects/rocprofiler-sdk/source/lib/common/container/stable_vector.hpp index 8b95e8b3af..fcf972aa80 100644 --- a/projects/rocprofiler-sdk/source/lib/common/container/stable_vector.hpp +++ b/projects/rocprofiler-sdk/source/lib/common/container/stable_vector.hpp @@ -24,6 +24,7 @@ #include "lib/common/container/operators.hpp" #include "lib/common/container/static_vector.hpp" +#include "lib/common/defines.hpp" #include #include @@ -359,8 +360,8 @@ stable_vector::at(size_type i) { if(ROCPROFILER_UNLIKELY(i >= size())) { - throw ::rocprofiler::exception("stable_vector::at(" + std::to_string(i) + - "). size is " + std::to_string(size())); + throw std::out_of_range("stable_vector::at(" + std::to_string(i) + "). size is " + + std::to_string(size())); } return operator[](i); diff --git a/projects/rocprofiler-sdk/source/lib/common/container/static_vector.hpp b/projects/rocprofiler-sdk/source/lib/common/container/static_vector.hpp index b6c56662f0..15cfe6f529 100644 --- a/projects/rocprofiler-sdk/source/lib/common/container/static_vector.hpp +++ b/projects/rocprofiler-sdk/source/lib/common/container/static_vector.hpp @@ -23,6 +23,7 @@ #pragma once #include "lib/common/container/c_array.hpp" +#include "lib/common/defines.hpp" #include #include @@ -141,8 +142,8 @@ static_vector::operator=(std::initializer_list&& _v) { if(ROCPROFILER_UNLIKELY(_v.size() > N)) { - throw exception( - std::string{"static_vector::operator=(initializer_list) size > "} + std::to_string(N)); + throw std::out_of_range(std::string{"static_vector::operator=(initializer_list) size > "} + + std::to_string(N)); } clear(); @@ -196,14 +197,21 @@ static_vector::emplace_back(Args&&... _v) auto _idx = m_size++; if(_idx >= N) { - throw exception( - std::string{"static_vector::emplace_back - reached capacity "} + std::to_string(N)); + throw std::out_of_range(std::string{"static_vector::emplace_back - reached capacity "} + + std::to_string(N)); } - if constexpr(std::is_assignable(_v))...>::value) - m_data[_idx] = {std::forward(_v)...}; + if constexpr(sizeof...(Args) > 0) + { + if constexpr(std::is_assignable(_v))...>::value) + m_data[_idx] = {std::forward(_v)...}; + else + m_data[_idx] = Tp{std::forward(_v)...}; + } else - m_data[_idx] = Tp{std::forward(_v)...}; + { + m_data[_idx] = {}; + } return m_data[_idx]; } diff --git a/projects/rocprofiler-sdk/source/lib/common/utility.hpp b/projects/rocprofiler-sdk/source/lib/common/utility.hpp new file mode 100644 index 0000000000..9dac154279 --- /dev/null +++ b/projects/rocprofiler-sdk/source/lib/common/utility.hpp @@ -0,0 +1,49 @@ +// MIT License +// +// Copyright (c) 2023 ROCm Developer Tools +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#pragma once + +#include +#include +#include +#include + +namespace rocprofiler +{ +namespace common +{ +inline uint64_t +get_tid() +{ + // system calls are expensive so store this in a thread-local + static thread_local uint64_t _v = ::syscall(__NR_gettid); + return _v; +} + +inline uint64_t +timestamp_ns() +{ + // TODO(jrmadsen): this should be updated to the HSA method + return std::chrono::steady_clock::now().time_since_epoch().count(); +} +} // namespace common +} // namespace rocprofiler