oclh_get_dev_name_by_idx.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536
  1. #include <string.h>
  2. #include <oclh.h>
  3. #include <oclh_h_base_dev_clapi_wrappers.h>
  4. int32_t main(int32_t argc, char *argv[]) {
  5. /**/
  6. #define __CLEAN_GET_DEV_NAME_BY_IDX_INFRASTRUCTURE_AND_EXIT \
  7. { if(pcDevName) { free(pcDevName); pcDevName=NULL; } \
  8. _ghf_wipeDevList(&DevLst); _ghf_wipeWS(&tmpWS); \
  9. _ghf_wipeLog(&Log); return(err); }
  10. /**/
  11. int32_t err=0;
  12. if(argc<2) return(1);
  13. {
  14. _GHT_LOG Log=_ghf_declLog();
  15. _GHT_WRKSET tmpWS=_ghf_declWS();
  16. cl_uint cluDevIdx=(cl_uint)strtoul((argc>1)?argv[1]:"",NULL,10);
  17. char* pcDevName=NULL;
  18. cl_device_id* DevLst=NULL;
  19. if((err=_ghf_genrLog(&Log,"/dev/null")))
  20. __CLEAN_GET_DEV_NAME_BY_IDX_INFRASTRUCTURE_AND_EXIT;
  21. tmpWS.Log=Log; tmpWS.pwSetAddr=&tmpWS;
  22. if((err=_ghf_buildDevList(tmpWS,&DevLst)))
  23. __CLEAN_GET_DEV_NAME_BY_IDX_INFRASTRUCTURE_AND_EXIT;
  24. pcDevName=_ghf_getDevInf_charptr(DevLst[cluDevIdx],CL_DEVICE_NAME,&err);
  25. if(err) __CLEAN_GET_DEV_NAME_BY_IDX_INFRASTRUCTURE_AND_EXIT;
  26. __ghf_removePreNPostSpacesFromCharPtr(pcDevName);
  27. __ghf_replaceIllegalFSCharsInCharPtr(pcDevName);
  28. __ghf_replaceSpacesWithUnderscoreInCharPtr(pcDevName);
  29. printf("%s\n",pcDevName);
  30. __CLEAN_GET_DEV_NAME_BY_IDX_INFRASTRUCTURE_AND_EXIT;
  31. }
  32. /**/
  33. #undef __CLEAN_GET_DEV_NAME_BY_IDX_INFRASTRUCTURE_AND_EXIT
  34. /**/
  35. }