LINT: Add cpplint, clang-format and pre-commit support

Change-Id: I3cbb787ef27d90486b212dfb1a8c77c460acc2ac
Signed-off-by: Galantsev, Dmitrii <dmitrii.galantsev@amd.com>


[ROCm/rdc commit: 434e40305d]
This commit is contained in:
Galantsev, Dmitrii
2023-12-04 15:24:34 -06:00
parent 61cf14d7cc
commit ea624cbb7c
137 changed files with 9122 additions and 10469 deletions
+97 -110
View File
@@ -19,140 +19,127 @@ 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.
*/
#include <getopt.h>
#include <unistd.h>
#include "rdc_lib/rdc_common.h"
#include "rdc/rdc.h"
#include "rdc_lib/RdcException.h"
#include "RdciDiscoverySubSystem.h"
#include <getopt.h>
#include <unistd.h>
#include "rdc/rdc.h"
#include "rdc_lib/RdcException.h"
#include "rdc_lib/rdc_common.h"
namespace amd {
namespace rdc {
RdciDiscoverySubSystem::RdciDiscoverySubSystem() : show_help_(false) {
}
RdciDiscoverySubSystem::RdciDiscoverySubSystem() : show_help_(false) {}
void RdciDiscoverySubSystem::parse_cmd_opts(int argc, char ** argv) {
const int HOST_OPTIONS = 1000;
const int JSON_OPTIONS = 1001;
const struct option long_options[] = {
{"host", required_argument, nullptr, HOST_OPTIONS },
{"help", optional_argument, nullptr, 'h' },
{"unauth", optional_argument, nullptr, 'u' },
{"list", optional_argument, nullptr, 'l' },
{"json", optional_argument, nullptr, JSON_OPTIONS },
{ nullptr, 0 , nullptr, 0 }
};
void RdciDiscoverySubSystem::parse_cmd_opts(int argc, char** argv) {
const int HOST_OPTIONS = 1000;
const int JSON_OPTIONS = 1001;
const struct option long_options[] = {
{"host", required_argument, nullptr, HOST_OPTIONS}, {"help", optional_argument, nullptr, 'h'},
{"unauth", optional_argument, nullptr, 'u'}, {"list", optional_argument, nullptr, 'l'},
{"json", optional_argument, nullptr, JSON_OPTIONS}, {nullptr, 0, nullptr, 0}};
int option_index = 0;
int opt = 0;
bool is_list = false;
int option_index = 0;
int opt = 0;
bool is_list = false;
while ((opt = getopt_long(argc, argv, "hlu",
long_options, &option_index)) != -1) {
switch (opt) {
case HOST_OPTIONS:
ip_port_ = optarg;
break;
case JSON_OPTIONS:
set_json_output(true);
break;
case 'h':
show_help_ = true;
return;
case 'u':
use_auth_ = false;
break;
case 'l':
is_list = true;
break;
default:
show_help();
throw RdcException(RDC_ST_BAD_PARAMETER,
"Unknown command line options");
}
}
if (!is_list) {
while ((opt = getopt_long(argc, argv, "hlu", long_options, &option_index)) != -1) {
switch (opt) {
case HOST_OPTIONS:
ip_port_ = optarg;
break;
case JSON_OPTIONS:
set_json_output(true);
break;
case 'h':
show_help_ = true;
return;
case 'u':
use_auth_ = false;
break;
case 'l':
is_list = true;
break;
default:
show_help();
throw RdcException(RDC_ST_BAD_PARAMETER,
"Need to specify operations");
throw RdcException(RDC_ST_BAD_PARAMETER, "Unknown command line options");
}
}
if (!is_list) {
show_help();
throw RdcException(RDC_ST_BAD_PARAMETER, "Need to specify operations");
}
}
void RdciDiscoverySubSystem::show_help() const {
if (is_json_output()) return;
std::cout << " discovery -- Used to discover and identify GPUs "
<< "and their attributes.\n\n";
std::cout << "Usage\n";
std::cout << " rdci discovery [--host <IP/FQDN>:port] [--json]"
if (is_json_output()) return;
std::cout << " discovery -- Used to discover and identify GPUs "
<< "and their attributes.\n\n";
std::cout << "Usage\n";
std::cout << " rdci discovery [--host <IP/FQDN>:port] [--json]"
<< " [-u] -l\n";
std::cout << "\nFlags:\n";
show_common_usage();
std::cout << " --json "
<< "Output using json.\n";
std::cout << " -l --list list GPU discovered"
<<" on the system\n";
std::cout << "\nFlags:\n";
show_common_usage();
std::cout << " --json "
<< "Output using json.\n";
std::cout << " -l --list list GPU discovered"
<< " on the system\n";
}
void RdciDiscoverySubSystem::process() {
if (show_help_) {
return show_help();
}
if (show_help_) {
return show_help();
}
uint32_t gpu_index_list[RDC_MAX_NUM_DEVICES];
uint32_t count = 0;
rdc_status_t result = rdc_device_get_all(rdc_handle_,
gpu_index_list, &count);
if (result != RDC_ST_OK) {
throw RdcException(result, "Fail to get device information");
}
if (count == 0) {
if (is_json_output()) {
std::cout << "\"gpus\" : [], \"status\": \"ok\"";
} else {
std::cout << "No GPUs find on the system\n";
}
return;
uint32_t gpu_index_list[RDC_MAX_NUM_DEVICES];
uint32_t count = 0;
rdc_status_t result = rdc_device_get_all(rdc_handle_, gpu_index_list, &count);
if (result != RDC_ST_OK) {
throw RdcException(result, "Fail to get device information");
}
if (count == 0) {
if (is_json_output()) {
std::cout << "\"gpus\" : [], \"status\": \"ok\"";
} else {
std::cout << "No GPUs find on the system\n";
}
return;
}
if (is_json_output()) {
std::cout << "\"gpus\" : [";
} else {
std::cout << count << " GPUs found.\n";
std::cout << "------------------------------------------------"
<< "-----------------\n";
std::cout << "GPU Index\t Device Information\n";
}
for (uint32_t i = 0; i < count; i++) {
rdc_device_attributes_t attribute;
result = rdc_device_get_attributes(rdc_handle_,
gpu_index_list[i], &attribute);
if (result != RDC_ST_OK) {
return;
}
if (is_json_output()) {
std::cout << "{\"gpu_index\": \"" << i << "\", \"device_name\": \""
<< attribute.device_name << "\"}";
if (i != count -1) {
std::cout << ",";
}
} else {
std::cout << i << "\t\t" << attribute.device_name <<std::endl;
}
}
if (is_json_output()) {
std::cout << ']';
} else {
std::cout << "------------------------------------------------"
if (is_json_output()) {
std::cout << "\"gpus\" : [";
} else {
std::cout << count << " GPUs found.\n";
std::cout << "------------------------------------------------"
<< "-----------------\n";
std::cout << "GPU Index\t Device Information\n";
}
for (uint32_t i = 0; i < count; i++) {
rdc_device_attributes_t attribute;
result = rdc_device_get_attributes(rdc_handle_, gpu_index_list[i], &attribute);
if (result != RDC_ST_OK) {
return;
}
if (is_json_output()) {
std::cout << "{\"gpu_index\": \"" << i << "\", \"device_name\": \"" << attribute.device_name
<< "\"}";
if (i != count - 1) {
std::cout << ",";
}
} else {
std::cout << i << "\t\t" << attribute.device_name << std::endl;
}
}
if (is_json_output()) {
std::cout << ']';
} else {
std::cout << "------------------------------------------------"
<< "-----------------\n";
}
}
} // namespace rdc
} // namespace amd