88#define UCS_DEVICE_CODE_H
99
1010#include <ucs/sys/compiler_def.h>
11+ #include <ucs/type/status.h>
1112#include <stdint.h>
1213
1314/*
@@ -35,7 +36,7 @@ typedef enum {
3536} ucs_device_level_t ;
3637
3738
38- static UCS_F_ALWAYS_INLINE const char *
39+ UCS_F_DEVICE const char *
3940ucs_device_level_name (ucs_device_level_t level )
4041{
4142 switch (level ) {
@@ -87,10 +88,10 @@ UCS_F_DEVICE void ucs_device_atomic64_write(uint64_t *ptr, uint64_t value)
8788
8889
8990/* Helper macro to print a message from a device function including the
90- * thread and block indices */
91+ * thread and block indices, file, line, and function */
9192#define ucs_device_printf (_title , _fmt , ...) \
92- printf("(%d:%d) %6s " _fmt "\n", threadIdx.x, blockIdx.x, _title, \
93- ##__VA_ARGS__)
93+ printf("(%d:%d) %6s %s:%d %s: " _fmt "\n", threadIdx.x, blockIdx.x, _title, \
94+ __FILE__, __LINE__, __func__, ##__VA_ARGS__)
9495
9596/* Print an error message from a device function */
9697#define ucs_device_error (_fmt , ...) \
@@ -101,4 +102,79 @@ UCS_F_DEVICE void ucs_device_atomic64_write(uint64_t *ptr, uint64_t value)
101102#define ucs_device_debug (_fmt , ...) \
102103 ucs_device_printf("DEBUG", _fmt, ##__VA_ARGS__)
103104
105+
106+ /**
107+ * @brief Device compatible status code to string conversion
108+ *
109+ * This function provides status code to string conversion that can be called
110+ * from device code. Returns a short string representation of the status code.
111+ *
112+ * @param [in] status Status code to convert
113+ *
114+ * @return Short string representation of the status code
115+ */
116+ UCS_F_DEVICE const char * ucs_device_status_string (ucs_status_t status )
117+ {
118+ switch (status ) {
119+ case UCS_OK :
120+ return "Success" ;
121+ case UCS_INPROGRESS :
122+ return "Operation in progress" ;
123+ case UCS_ERR_NO_MESSAGE :
124+ return "No pending message" ;
125+ case UCS_ERR_NO_RESOURCE :
126+ return "No resources are available to initiate the operation" ;
127+ case UCS_ERR_IO_ERROR :
128+ return "Input/output error" ;
129+ case UCS_ERR_NO_MEMORY :
130+ return "Out of memory" ;
131+ case UCS_ERR_INVALID_PARAM :
132+ return "Invalid parameter" ;
133+ case UCS_ERR_UNREACHABLE :
134+ return "Destination is unreachable" ;
135+ case UCS_ERR_INVALID_ADDR :
136+ return "Address not valid" ;
137+ case UCS_ERR_NOT_IMPLEMENTED :
138+ return "Function not implemented" ;
139+ case UCS_ERR_MESSAGE_TRUNCATED :
140+ return "Message truncated" ;
141+ case UCS_ERR_NO_PROGRESS :
142+ return "No progress" ;
143+ case UCS_ERR_BUFFER_TOO_SMALL :
144+ return "Provided buffer is too small" ;
145+ case UCS_ERR_NO_ELEM :
146+ return "No such element" ;
147+ case UCS_ERR_SOME_CONNECTS_FAILED :
148+ return "Failed to connect some of the requested endpoints" ;
149+ case UCS_ERR_NO_DEVICE :
150+ return "No such device" ;
151+ case UCS_ERR_BUSY :
152+ return "Device is busy" ;
153+ case UCS_ERR_CANCELED :
154+ return "Request canceled" ;
155+ case UCS_ERR_SHMEM_SEGMENT :
156+ return "Shared memory error" ;
157+ case UCS_ERR_ALREADY_EXISTS :
158+ return "Element already exists" ;
159+ case UCS_ERR_OUT_OF_RANGE :
160+ return "Index out of range" ;
161+ case UCS_ERR_TIMED_OUT :
162+ return "Operation timed out" ;
163+ case UCS_ERR_EXCEEDS_LIMIT :
164+ return "User-defined limit was reached" ;
165+ case UCS_ERR_UNSUPPORTED :
166+ return "Unsupported operation" ;
167+ case UCS_ERR_REJECTED :
168+ return "Operation rejected by remote peer" ;
169+ case UCS_ERR_NOT_CONNECTED :
170+ return "Endpoint is not connected" ;
171+ case UCS_ERR_CONNECTION_RESET :
172+ return "Connection reset by remote peer" ;
173+ case UCS_ERR_ENDPOINT_TIMEOUT :
174+ return "Endpoint timeout" ;
175+ default :
176+ return "Unknown error" ;
177+ };
178+ }
179+
104180#endif
0 commit comments