Skip to content

Commit 0ad484d

Browse files
committed
Use a map for include_files
Signed-off-by: Julian Oppermann <[email protected]>
1 parent 85ef513 commit 0ad484d

File tree

2 files changed

+40
-20
lines changed

2 files changed

+40
-20
lines changed

sycl/include/sycl/kernel_bundle.hpp

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,22 @@
2626
#include <sycl/ext/oneapi/properties/property.hpp> // build_options
2727
#include <sycl/ext/oneapi/properties/property_value.hpp> // and log
2828

29+
#include <algorithm> // for copy
2930
#include <array> // for array
3031
#include <cstddef> // for std::byte
3132
#include <cstring> // for size_t, memcpy
3233
#include <functional> // for function
33-
#include <iterator> // for distance
34+
#include <iterator> // for distance, back_inserter
3435
#include <memory> // for shared_ptr, operator==, hash
3536
#if __has_include(<span>)
3637
#include <span>
3738
#endif
38-
#include <string> // for string
39-
#include <type_traits> // for enable_if_t, remove_refer...
40-
#include <utility> // for move
41-
#include <variant> // for hash
42-
#include <vector> // for vector
39+
#include <string> // for string
40+
#include <type_traits> // for enable_if_t, remove_refer...
41+
#include <unordered_map> // for unordered_map
42+
#include <utility> // for move
43+
#include <variant> // for hash
44+
#include <vector> // for vector
4345

4446
namespace sycl {
4547
inline namespace _V1 {
@@ -956,19 +958,17 @@ struct include_files
956958
detail::PropKind::IncludeFiles> {
957959
include_files() {}
958960
include_files(const std::string &name, const std::string &content) {
959-
record.emplace_back(std::make_pair(name, content));
961+
record.emplace(name, content);
960962
}
961963
void add(const std::string &name, const std::string &content) {
962-
if (std::find_if(record.begin(), record.end(), [&name](auto &p) {
963-
return p.first == name;
964-
}) != record.end()) {
964+
[[maybe_unused]] auto [it, ins] = record.try_emplace(name, content);
965+
if (!ins) {
965966
throw sycl::exception(make_error_code(errc::invalid),
966967
"Include file '" + name +
967968
"' is already registered");
968969
}
969-
record.emplace_back(std::make_pair(name, content));
970970
}
971-
std::vector<std::pair<std::string, std::string>> record;
971+
std::unordered_map<std::string, std::string> record;
972972
};
973973
using include_files_key = include_files;
974974

@@ -1125,7 +1125,10 @@ kernel_bundle<bundle_state::ext_oneapi_source> create_kernel_bundle_from_source(
11251125
const std::string &Source, PropertyListT props = {}) {
11261126
std::vector<std::pair<std::string, std::string>> IncludePairsVec;
11271127
if constexpr (props.template has_property<include_files>()) {
1128-
IncludePairsVec = props.template get_property<include_files>().record;
1128+
const std::unordered_map<std::string, std::string> &IncludePairs =
1129+
props.template get_property<include_files>().record;
1130+
std::copy(IncludePairs.begin(), IncludePairs.end(),
1131+
std::back_inserter(IncludePairsVec));
11291132
}
11301133

11311134
return detail::make_kernel_bundle_from_source(SyclContext, Language, Source,
@@ -1141,7 +1144,10 @@ kernel_bundle<bundle_state::ext_oneapi_source> create_kernel_bundle_from_source(
11411144
const std::vector<std::byte> &Bytes, PropertyListT props = {}) {
11421145
std::vector<std::pair<std::string, std::string>> IncludePairsVec;
11431146
if constexpr (props.template has_property<include_files>()) {
1144-
IncludePairsVec = props.template get_property<include_files>().record;
1147+
const std::unordered_map<std::string, std::string> &IncludePairs =
1148+
props.template get_property<include_files>().record;
1149+
std::copy(IncludePairs.begin(), IncludePairs.end(),
1150+
std::back_inserter(IncludePairsVec));
11451151
}
11461152

11471153
return detail::make_kernel_bundle_from_source(SyclContext, Language, Bytes,

sycl/test/abi/sycl_classes_abi_neutral_test.cpp

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,26 @@
2626

2727
// CHECK: 0 | struct sycl::ext::oneapi::experimental::include_files
2828
// CHECK-NEXT: 0 | struct sycl::ext::oneapi::experimental::detail::run_time_property_key
29-
// CHECK: 0 | class std::vector<struct std::pair<class std::basic_string<char>, class std::basic_string<char> > > record
30-
// CHECK-NEXT: 0 | struct std::_Vector_base<struct std::pair<class std::basic_string<char>, class std::basic_string<char> >, class std::allocator<struct std::pair<class std::basic_string<char>, class std::basic_string<char> > > > (base)
31-
// CHECK-NEXT: 0 | struct std::_Vector_base<struct std::pair<class std::basic_string<char>, class std::basic_string<char> >, class std::allocator<struct std::pair<class std::basic_string<char>, class std::basic_string<char> > > >::_Vector_impl _M_impl
32-
// CHECK-NEXT: 0 | class std::allocator<struct std::pair<class std::basic_string<char>, class std::basic_string<char> > > (base) (empty)
33-
// CHECK-NEXT: 0 | class {{(std::__new_allocator|__gnu_cxx::new_allocator)}}<struct std::pair<class std::basic_string<char>, class std::basic_string<char> > > (base) (empty)
34-
// CHECK-NEXT: 0 | {{(struct std::_Vector_base<struct std::pair<class std::basic_string<char>, class std::basic_string<char> >, class std::allocator<struct std::pair<class std::basic_string<char>, class std::basic_string<char> > > >::_Vector_impl_data \(base\)|pointer _M_start)}}
29+
// CHECK: 0 | class std::unordered_map<class std::basic_string<char>, class std::basic_string<char> > record
30+
// CHECK-NEXT: 0 | class std::_Hashtable<class std::basic_string<char>, struct std::pair<const class std::basic_string<char>, class std::basic_string<char> >, class std::allocator<struct std::pair<const class std::basic_string<char>, class std::basic_string<char> > >, struct std::__detail::_Select1st, struct std::equal_to<class std::basic_string<char> >, struct std::hash<string>, struct std::__detail::_Mod_range_hashing, struct std::__detail::_Default_ranged_hash, struct std::__detail::_Prime_rehash_policy, struct std::__detail::_Hashtable_traits<true, false, true> > _M_h
31+
// CHECK-NEXT: 0 | struct std::__detail::_Hashtable_base<class std::basic_string<char>, struct std::pair<const class std::basic_string<char>, class std::basic_string<char> >, struct std::__detail::_Select1st, struct std::equal_to<class std::basic_string<char> >, struct std::hash<string>, struct std::__detail::_Mod_range_hashing, struct std::__detail::_Default_ranged_hash, struct std::__detail::_Hashtable_traits<true, false, true> > (base) (empty)
32+
// CHECK-NEXT: 0 | struct std::__detail::_Hash_code_base<class std::basic_string<char>, struct std::pair<const class std::basic_string<char>, class std::basic_string<char> >, struct std::__detail::_Select1st, struct std::hash<string>, struct std::__detail::_Mod_range_hashing, struct std::__detail::_Default_ranged_hash, true> (base) (empty)
33+
// CHECK-NEXT: 0 | struct std::__detail::_Hashtable_ebo_helper<1, struct std::hash<string> > (base) (empty)
34+
// CHECK-NEXT: 0 | struct std::hash<string> (base) (empty)
35+
// CHECK-NEXT: 0 | struct std::__hash_base<unsigned long, class std::basic_string<char> > (base) (empty)
36+
// CHECK-NEXT: 0 | struct std::__detail::_Hashtable_ebo_helper<0, struct std::equal_to<class std::basic_string<char> > > (base) (empty)
37+
// CHECK-NEXT: 0 | struct std::equal_to<class std::basic_string<char> > (base) (empty)
38+
// CHECK-NEXT: 0 | struct std::binary_function<class std::basic_string<char>, class std::basic_string<char>, _Bool> (base) (empty)
39+
// CHECK-NEXT: 0 | struct std::__detail::_Map_base<class std::basic_string<char>, struct std::pair<const class std::basic_string<char>, class std::basic_string<char> >, class std::allocator<struct std::pair<const class std::basic_string<char>, class std::basic_string<char> > >, struct std::__detail::_Select1st, struct std::equal_to<class std::basic_string<char> >, struct std::hash<string>, struct std::__detail::_Mod_range_hashing, struct std::__detail::_Default_ranged_hash, struct std::__detail::_Prime_rehash_policy, struct std::__detail::_Hashtable_traits<true, false, true> > (base) (empty)
40+
// CHECK-NEXT: 0 | struct std::__detail::_Insert<class std::basic_string<char>, struct std::pair<const class std::basic_string<char>, class std::basic_string<char> >, class std::allocator<struct std::pair<const class std::basic_string<char>, class std::basic_string<char> > >, struct std::__detail::_Select1st, struct std::equal_to<class std::basic_string<char> >, struct std::hash<string>, struct std::__detail::_Mod_range_hashing, struct std::__detail::_Default_ranged_hash, struct std::__detail::_Prime_rehash_policy, struct std::__detail::_Hashtable_traits<true, false, true> > (base) (empty)
41+
// CHECK-NEXT: 0 | struct std::__detail::_Insert_base<class std::basic_string<char>, struct std::pair<const class std::basic_string<char>, class std::basic_string<char> >, class std::allocator<struct std::pair<const class std::basic_string<char>, class std::basic_string<char> > >, struct std::__detail::_Select1st, struct std::equal_to<class std::basic_string<char> >, struct std::hash<string>, struct std::__detail::_Mod_range_hashing, struct std::__detail::_Default_ranged_hash, struct std::__detail::_Prime_rehash_policy, struct std::__detail::_Hashtable_traits<true, false, true> > (base) (empty)
42+
// CHECK-NEXT: 0 | struct std::__detail::_Rehash_base<class std::basic_string<char>, struct std::pair<const class std::basic_string<char>, class std::basic_string<char> >, class std::allocator<struct std::pair<const class std::basic_string<char>, class std::basic_string<char> > >, struct std::__detail::_Select1st, struct std::equal_to<class std::basic_string<char> >, struct std::hash<string>, struct std::__detail::_Mod_range_hashing, struct std::__detail::_Default_ranged_hash, struct std::__detail::_Prime_rehash_policy, struct std::__detail::_Hashtable_traits<true, false, true> > (base) (empty)
43+
// CHECK-NEXT: 0 | struct std::__detail::_Equality<class std::basic_string<char>, struct std::pair<const class std::basic_string<char>, class std::basic_string<char> >, class std::allocator<struct std::pair<const class std::basic_string<char>, class std::basic_string<char> > >, struct std::__detail::_Select1st, struct std::equal_to<class std::basic_string<char> >, struct std::hash<string>, struct std::__detail::_Mod_range_hashing, struct std::__detail::_Default_ranged_hash, struct std::__detail::_Prime_rehash_policy, struct std::__detail::_Hashtable_traits<true, false, true> > (base) (empty)
44+
// CHECK-NEXT: 0 | struct std::__detail::_Hashtable_alloc<class std::allocator<struct std::__detail::_Hash_node<struct std::pair<const class std::basic_string<char>, class std::basic_string<char> >, true> > > (base) (empty)
45+
// CHECK-NEXT: 0 | struct std::__detail::_Hashtable_ebo_helper<0, class std::allocator<struct std::__detail::_Hash_node<struct std::pair<const class std::basic_string<char>, class std::basic_string<char> >, true> > > (base) (empty)
46+
// CHECK-NEXT: 0 | class std::allocator<struct std::__detail::_Hash_node<struct std::pair<const class std::basic_string<char>, class std::basic_string<char> >, true> > (base) (empty)
47+
// CHECK-NEXT: 0 | class {{(std::__new_allocator|__gnu_cxx::new_allocator)}}<struct std::__detail::_Hash_node<struct std::pair<const class std::basic_string<char>, class std::basic_string<char> >, true> > (base) (empty)
48+
// CHECK-NEXT: 0 | {{(struct std::_Enable_default_constructor<true, struct std::__detail::_Hash_node_base> \(base\) \(empty\))|(__buckets_ptr _M_buckets)}}
3549

3650
// CHECK: 0 | struct sycl::ext::oneapi::experimental::registered_names
3751
// CHECK-NEXT: 0 | struct sycl::ext::oneapi::experimental::detail::run_time_property_key

0 commit comments

Comments
 (0)