1 /*===-------------------------------------------------------------------------- 2 * ATMI (Asynchronous Task and Memory Interface) 3 * 4 * This file is distributed under the MIT License. See LICENSE.txt for details. 5 *===------------------------------------------------------------------------*/ 6 #include "internal.h" 7 #include "rt.h" 8 9 #ifndef _GNU_SOURCE 10 #define _GNU_SOURCE 11 #endif 12 13 #include <errno.h> 14 #include <iostream> 15 #include <pthread.h> 16 #include <sched.h> 17 #include <stdio.h> 18 19 /* 20 * Helper functions 21 */ get_atmi_error_string(atmi_status_t err)22const char *get_atmi_error_string(atmi_status_t err) { 23 switch (err) { 24 case ATMI_STATUS_SUCCESS: 25 return "ATMI_STATUS_SUCCESS"; 26 case ATMI_STATUS_UNKNOWN: 27 return "ATMI_STATUS_UNKNOWN"; 28 case ATMI_STATUS_ERROR: 29 return "ATMI_STATUS_ERROR"; 30 default: 31 return ""; 32 } 33 } 34 get_error_string(hsa_status_t err)35const char *get_error_string(hsa_status_t err) { 36 switch (err) { 37 case HSA_STATUS_SUCCESS: 38 return "HSA_STATUS_SUCCESS"; 39 case HSA_STATUS_INFO_BREAK: 40 return "HSA_STATUS_INFO_BREAK"; 41 case HSA_STATUS_ERROR: 42 return "HSA_STATUS_ERROR"; 43 case HSA_STATUS_ERROR_INVALID_ARGUMENT: 44 return "HSA_STATUS_ERROR_INVALID_ARGUMENT"; 45 case HSA_STATUS_ERROR_INVALID_QUEUE_CREATION: 46 return "HSA_STATUS_ERROR_INVALID_QUEUE_CREATION"; 47 case HSA_STATUS_ERROR_INVALID_ALLOCATION: 48 return "HSA_STATUS_ERROR_INVALID_ALLOCATION"; 49 case HSA_STATUS_ERROR_INVALID_AGENT: 50 return "HSA_STATUS_ERROR_INVALID_AGENT"; 51 case HSA_STATUS_ERROR_INVALID_REGION: 52 return "HSA_STATUS_ERROR_INVALID_REGION"; 53 case HSA_STATUS_ERROR_INVALID_SIGNAL: 54 return "HSA_STATUS_ERROR_INVALID_SIGNAL"; 55 case HSA_STATUS_ERROR_INVALID_QUEUE: 56 return "HSA_STATUS_ERROR_INVALID_QUEUE"; 57 case HSA_STATUS_ERROR_OUT_OF_RESOURCES: 58 return "HSA_STATUS_ERROR_OUT_OF_RESOURCES"; 59 case HSA_STATUS_ERROR_INVALID_PACKET_FORMAT: 60 return "HSA_STATUS_ERROR_INVALID_PACKET_FORMAT"; 61 case HSA_STATUS_ERROR_RESOURCE_FREE: 62 return "HSA_STATUS_ERROR_RESOURCE_FREE"; 63 case HSA_STATUS_ERROR_NOT_INITIALIZED: 64 return "HSA_STATUS_ERROR_NOT_INITIALIZED"; 65 case HSA_STATUS_ERROR_REFCOUNT_OVERFLOW: 66 return "HSA_STATUS_ERROR_REFCOUNT_OVERFLOW"; 67 case HSA_STATUS_ERROR_INCOMPATIBLE_ARGUMENTS: 68 return "HSA_STATUS_ERROR_INCOMPATIBLE_ARGUMENTS"; 69 case HSA_STATUS_ERROR_INVALID_INDEX: 70 return "HSA_STATUS_ERROR_INVALID_INDEX"; 71 case HSA_STATUS_ERROR_INVALID_ISA: 72 return "HSA_STATUS_ERROR_INVALID_ISA"; 73 case HSA_STATUS_ERROR_INVALID_ISA_NAME: 74 return "HSA_STATUS_ERROR_INVALID_ISA_NAME"; 75 case HSA_STATUS_ERROR_INVALID_CODE_OBJECT: 76 return "HSA_STATUS_ERROR_INVALID_CODE_OBJECT"; 77 case HSA_STATUS_ERROR_INVALID_EXECUTABLE: 78 return "HSA_STATUS_ERROR_INVALID_EXECUTABLE"; 79 case HSA_STATUS_ERROR_FROZEN_EXECUTABLE: 80 return "HSA_STATUS_ERROR_FROZEN_EXECUTABLE"; 81 case HSA_STATUS_ERROR_INVALID_SYMBOL_NAME: 82 return "HSA_STATUS_ERROR_INVALID_SYMBOL_NAME"; 83 case HSA_STATUS_ERROR_VARIABLE_ALREADY_DEFINED: 84 return "HSA_STATUS_ERROR_VARIABLE_ALREADY_DEFINED"; 85 case HSA_STATUS_ERROR_VARIABLE_UNDEFINED: 86 return "HSA_STATUS_ERROR_VARIABLE_UNDEFINED"; 87 case HSA_STATUS_ERROR_EXCEPTION: 88 return "HSA_STATUS_ERROR_EXCEPTION"; 89 } 90 } 91 92 namespace core { 93 /* 94 * Environment variables 95 */ GetEnvAll()96void Environment::GetEnvAll() { 97 std::string var = GetEnv("ATMI_HELP"); 98 if (!var.empty()) { 99 std::cout << "ATMI_MAX_HSA_QUEUE_SIZE : positive integer" << std::endl 100 << "ATMI_DEBUG : 1 for printing out trace/debug info" 101 << std::endl; 102 exit(0); 103 } 104 105 var = GetEnv("ATMI_MAX_HSA_QUEUE_SIZE"); 106 if (!var.empty()) 107 max_queue_size_ = std::stoi(var); 108 109 var = GetEnv("ATMI_DEBUG"); 110 if (!var.empty()) 111 debug_mode_ = std::stoi(var); 112 } 113 } // namespace core 114