Skip to content

Commit cf090c5

Browse files
NB4444assistant-librarian[bot]
authored andcommitted
[rocm-libraries] ROCm/rocm-libraries#5753 (commit 6c13446)
Fix compile warnings rocthrust and hipcub ## Motivation rocthrust and hipcub fail with -Werror ## Technical Details Needed to silence one flag, for a specific test `--offload-compress` was not used in resource-spec tests.. And some other minor changes in rocthrust and hipcub. It should not change any functionality. ## Test Plan Tests still should pass. ## Test Result Tests pass. ## Submission Checklist - [ ] Look over the contributing guidelines at https://github.com/ROCm/ROCm/blob/develop/CONTRIBUTING.md#pull-requests.
1 parent a02347d commit cf090c5

2 files changed

Lines changed: 89 additions & 90 deletions

File tree

test/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# MIT License
22
#
3-
# Copyright (c) 2017-2025 Advanced Micro Devices, Inc. All rights reserved.
3+
# Copyright (c) 2017-2026 Advanced Micro Devices, Inc. All rights reserved.
44
#
55
# Permission is hereby granted, free of charge, to any person obtaining a copy
66
# of this software and associated documentation files (the "Software"), to deal
@@ -69,6 +69,9 @@ set(GEN_RES_SPEC_PATH ${CMAKE_SOURCE_DIR}/test/generate_resource_spec.cpp)
6969
add_executable(generate_resource_spec ${GEN_RES_SPEC_PATH})
7070
set_target_properties(generate_resource_spec PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")
7171
target_link_libraries(generate_resource_spec PRIVATE hip::host)
72+
# This test may still get the offload-compress flag passed. Since it does not include any kernel
73+
# code it will give an unused-command-line-argument warning.
74+
target_compile_options(generate_resource_spec PRIVATE "-Wno-unused-command-line-argument")
7275

7376
# hipCUB tests
7477
add_subdirectory(hipcub)

test/generate_resource_spec.cpp

Lines changed: 85 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -47,113 +47,109 @@
4747

4848
#include <hip/hip_runtime_api.h>
4949

50+
#include <algorithm>
5051
#include <cstdlib>
51-
#include <iostream>
5252
#include <fstream>
53+
#include <iostream>
5354
#include <map>
5455
#include <vector>
55-
#include <algorithm>
5656

57-
#define HIP_CHECK(expression) \
58-
{ \
59-
const hipError_t status = expression; \
60-
if (status != hipSuccess) \
61-
{ \
62-
std::cerr << "HIP error " << status \
63-
<< ": " << hipGetErrorString(status) \
64-
<< " at " << __FILE__ << ":" \
65-
<< __LINE__ << std::endl; \
66-
std::exit(EXIT_FAILURE); \
67-
} \
68-
}
57+
#define HIP_CHECK(expression) \
58+
{ \
59+
const hipError_t status = expression; \
60+
if(status != hipSuccess) \
61+
{ \
62+
std::cerr << "HIP error " << status << ": " << hipGetErrorString(status) << " at " \
63+
<< __FILE__ << ":" << __LINE__ << std::endl; \
64+
std::exit(EXIT_FAILURE); \
65+
} \
66+
}
6967

7068
int main(int argc, char* argv[])
7169
{
72-
if (argc != 2)
73-
{
74-
std::cout << "Usage: ./enum_devices <output file path>" << std::endl;
75-
std::exit(EXIT_FAILURE);
76-
}
70+
if(argc != 2)
71+
{
72+
std::cout << "Usage: ./enum_devices <output file path>" << std::endl;
73+
std::exit(EXIT_FAILURE);
74+
}
7775

78-
std::ofstream out_file;
79-
out_file.open(argv[1]);
76+
std::ofstream out_file;
77+
out_file.open(argv[1]);
8078

81-
// Figure out how many devices are in the system.
79+
// Figure out how many devices are in the system.
8280
int dev_count;
8381
HIP_CHECK(hipGetDeviceCount(&dev_count));
8482

85-
// There could be more than one device of each type.
86-
// Build a mapping of gfxID (string) to a vector of device IDs (unsigned ints).
87-
std::map<std::string, std::vector<unsigned int>> names_to_ids;
88-
// This entry will hold all device IDs.
89-
names_to_ids["gpus"] = {};
83+
// There could be more than one device of each type.
84+
// Build a mapping of gfxID (string) to a vector of device IDs (unsigned ints).
85+
std::map<std::string, std::vector<unsigned int>> names_to_ids;
86+
// This entry will hold all device IDs.
87+
names_to_ids["gpus"] = {};
9088

91-
// Populate the map
92-
for (unsigned int dev_id = 0; dev_id < dev_count; ++dev_id)
89+
// Populate the map
90+
for(unsigned int dev_id = 0; dev_id < static_cast<unsigned int>(dev_count); ++dev_id)
9391
{
9492
hipDeviceProp_t dev_prop;
9593
HIP_CHECK(hipGetDeviceProperties(&dev_prop, dev_id));
96-
std::string name(dev_prop.gcnArchName);
97-
98-
if (names_to_ids.find(name) == names_to_ids.end())
99-
names_to_ids[name] = std::vector<unsigned int>({dev_id});
100-
else
101-
names_to_ids[name].push_back(dev_id);
102-
103-
// Add every device ID to the "gpus" entry
104-
names_to_ids["gpus"].push_back(dev_id);
94+
std::string name(dev_prop.gcnArchName);
95+
96+
if(names_to_ids.find(name) == names_to_ids.end())
97+
names_to_ids[name] = std::vector<unsigned int>({dev_id});
98+
else
99+
names_to_ids[name].push_back(dev_id);
100+
101+
// Add every device ID to the "gpus" entry
102+
names_to_ids["gpus"].push_back(dev_id);
105103
}
106104

107-
// Begin the JSON output. The first few lines are boilerplate:
108-
out_file << "{" << std::endl <<
109-
" \"version\": {" << std::endl <<
110-
" \"major\": 1," << std::endl <<
111-
" \"minor\": 0" << std::endl <<
112-
" }," << std::endl <<
113-
" \"local\": [" << std::endl <<
114-
" {" << std::endl;
115-
116-
// Add one object for each gfxID.
117-
// Each gfxID-keyed object will contain an array of device IDs.
118-
int key_index = 0;
119-
for (auto& name_it : names_to_ids)
120-
{
121-
out_file << " \"" << name_it.first << "\": [" << std::endl;
122-
123-
// The gfxIDs (names) are already sorted by the map, but the
124-
// device IDs may not be in order.
125-
// Sorting them is not technically necessary, but it's nice
126-
// to have a consistent output on each run so that the resource
127-
// spec file stays the same.
128-
std::sort(name_it.second.begin(), name_it.second.end());
129-
int id_index = 0;
130-
for (const auto& id_it : name_it.second)
131-
{
132-
out_file << " {" << std::endl;
133-
// Note: ctest expects ids to be specified as a string (quoted), not an integer.
134-
out_file << " \"id\": \"" << id_it << "\"" << std::endl;
135-
out_file << " }";
136-
137-
if (id_index < name_it.second.size() - 1)
138-
out_file << ",";
139-
out_file << std::endl;
140-
id_index++;
141-
}
142-
143-
out_file << " ]";
144-
145-
if (key_index < names_to_ids.size() - 1)
146-
out_file << ",";
147-
out_file << std::endl;
148-
key_index++;
149-
}
150-
151-
// Close out the remaining open objects and arrays.
152-
out_file << " }" << std::endl <<
153-
" ]" << std::endl <<
154-
"}" << std::endl;
155-
156-
out_file.close();
157-
105+
// Begin the JSON output. The first few lines are boilerplate:
106+
out_file << "{" << std::endl
107+
<< " \"version\": {" << std::endl
108+
<< " \"major\": 1," << std::endl
109+
<< " \"minor\": 0" << std::endl
110+
<< " }," << std::endl
111+
<< " \"local\": [" << std::endl
112+
<< " {" << std::endl;
113+
114+
// Add one object for each gfxID.
115+
// Each gfxID-keyed object will contain an array of device IDs.
116+
unsigned int key_index = 0;
117+
for(auto& name_it : names_to_ids)
118+
{
119+
out_file << " \"" << name_it.first << "\": [" << std::endl;
120+
121+
// The gfxIDs (names) are already sorted by the map, but the
122+
// device IDs may not be in order.
123+
// Sorting them is not technically necessary, but it's nice
124+
// to have a consistent output on each run so that the resource
125+
// spec file stays the same.
126+
std::sort(name_it.second.begin(), name_it.second.end());
127+
unsigned int id_index = 0;
128+
for(const auto& id_it : name_it.second)
129+
{
130+
out_file << " {" << std::endl;
131+
// Note: ctest expects ids to be specified as a string (quoted), not an integer.
132+
out_file << " \"id\": \"" << id_it << "\"" << std::endl;
133+
out_file << " }";
134+
135+
if(id_index < name_it.second.size() - 1)
136+
out_file << ",";
137+
out_file << std::endl;
138+
id_index++;
139+
}
140+
141+
out_file << " ]";
142+
143+
if(key_index < names_to_ids.size() - 1)
144+
out_file << ",";
145+
out_file << std::endl;
146+
key_index++;
147+
}
148+
149+
// Close out the remaining open objects and arrays.
150+
out_file << " }" << std::endl << " ]" << std::endl << "}" << std::endl;
151+
152+
out_file.close();
153+
158154
return EXIT_SUCCESS;
159155
}

0 commit comments

Comments
 (0)