Fichiers
rocm-systems/projects/rocm-core/rocm_version.cpp
T

Les révisions dans .git-blame-ignore-revs sont ignorées. Vous pouvez quand même voir ces blâmes.

86 lignes
2.4 KiB
C++
Brut Vue normale Historique

2025-10-17 09:10:18 +05:30
//Copyright © Advanced Micro Devices, Inc., or its affiliates.
2025-10-17 09:10:18 +05:30
//SPDX-License-Identifier: MIT
2022-10-18 10:35:37 +05:30
#include "rocm_version.h"
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
2025-10-17 09:10:18 +05:30
#define NULL_CHECK(ptr) if(!ptr) return VerIncorrectParameters;
2022-10-18 10:35:37 +05:30
#define CHECK_AND_REPORT_API_RESULT(val) do { \
if(VerSuccess != val) { \
2025-10-17 09:10:18 +05:30
const char *ErrStrings[VerErrorMAX]= { \
"VerSuccess", \
"VerIncorrectParameters", \
"VerMemoryAllocationFailed", \
"VerValuesNotDefined" \
}; \
2022-10-18 10:35:37 +05:30
fprintf(stderr, " API returned : %s \n", ErrStrings[val]); \
fflush(stderr); \
return val; \
} \
}while(0);
VerErrors getROCmVersion(unsigned int* Major, unsigned int* Minor, unsigned int* Patch) {
NULL_CHECK(Major)
NULL_CHECK(Minor)
NULL_CHECK(Patch)
*Major=ROCM_VERSION_MAJOR;
*Minor=ROCM_VERSION_MINOR;
*Patch=ROCM_VERSION_PATCH;
return VerSuccess;
}
2025-10-17 09:10:18 +05:30
static VerErrors getBuildInfo( char* InfoString, int length_of_the_buffer ) {
NULL_CHECK(InfoString);
2022-10-18 10:35:37 +05:30
#if defined(ROCM_BUILD_INFO)
2025-10-17 09:10:18 +05:30
if(length_of_the_buffer<=strlen(ROCM_BUILD_INFO)){
fprintf(stderr, "\n Error :: Buffer is less than adequate size required\n");
fflush(stderr);
return VerIncorrectParameters;
}
snprintf(InfoString, length_of_the_buffer, "%s", ROCM_BUILD_INFO);
return VerSuccess;
2022-10-18 10:35:37 +05:30
#else
return VerValuesNotDefined;
2025-10-17 09:10:18 +05:30
#endif //end definition checker
2022-10-18 10:35:37 +05:30
}
2025-10-17 09:10:18 +05:30
VerErrors printBuildInfo() {
int len_of_buffer_to_be_created = 0;
VerErrors apiret=VerSuccess;
2022-10-18 10:35:37 +05:30
#if defined(ROCM_BUILD_INFO)
2025-10-17 09:10:18 +05:30
len_of_buffer_to_be_created = 1 + strlen(ROCM_BUILD_INFO);//additional char for null termination
2022-10-18 10:35:37 +05:30
#else
return VerValuesNotDefined;
2025-10-17 09:10:18 +05:30
#endif //end definition checker
// len_of_buffer_to_be_created is now strlen(ROCM_BUILD_INFO) + 1
char* cstr=(char*) malloc(len_of_buffer_to_be_created);
if(cstr){
apiret=getBuildInfo(cstr,len_of_buffer_to_be_created);
if(VerSuccess != apiret) {
free(cstr);
}
CHECK_AND_REPORT_API_RESULT(apiret);
printf("\n Build Info of lib = [%s] \n",cstr);
//All good lets free
free(cstr);
return VerSuccess;
}
fprintf(stderr, "\n malloc failed for length [%d] \n",len_of_buffer_to_be_created);
fflush(stderr);
return VerMemoryAllocationFailed;
2022-10-18 10:35:37 +05:30
}