void context_clear(context_t* context) { int p, d; cl_int err; for (p = 0; p < context->plat_count; p++) { for (d = 0; d < context->dev_on_plat[p]; d++) { err = clReleaseCommandQueue(context->cmd[p][d]); #ifdef DEBUG printf("clReleaseCommandQueue [ %s ]\n", err_to_str(err)); #endif err = clReleaseContext(context->contexts[p][d]); #ifdef DEBUG printf("clReleaseContext [ %s ]\n", err_to_str(err)); #endif } } free_ptr_2d((void**) context->cmd, context->plat_count); free_ptr_2d((void**) context->contexts, context->plat_count); // free_ptr_2d((void**) context->dev_prop, context->plat_count); free_ptr_2d((void**) context->dev, context->plat_count); free_ptr_1d(context->dev_on_plat); free_ptr_1d(context->plat); context->plat_count = 0; context->total_dev_count = 0; context->dev_type = CL_DEVICE_TYPE_GPU; free_ptr_1d(context); }
int main(int argc, char** argv) { pthread_t threadid; int ret; pthread_mutex_init(&s_mutex, 0); pthread_cond_init(&s_cond, 0); pthread_create(&threadid, 0, thread_func, 0); pthread_mutex_lock(&s_mutex); while (s_i == 0) pthread_cond_wait(&s_cond, &s_mutex); pthread_mutex_unlock(&s_mutex); ret = pthread_cond_destroy(&s_cond); fprintf(stderr, "First pthread_cond_destroy() call returned %s.\n", err_to_str(ret)); pthread_mutex_lock(&s_mutex); s_i = 2; pthread_cond_signal(&s_cond); pthread_mutex_unlock(&s_mutex); pthread_join(threadid, 0); ret = pthread_cond_destroy(&s_cond); fprintf(stderr, "Second pthread_cond_destroy() call returned %s.\n", err_to_str(ret)); pthread_mutex_destroy(&s_mutex); return 0; }
struct mwReturnCodeDesc *mwGetReturnCodeDesc(guint32 code) { struct mwReturnCodeDesc *rcDesc = g_new(struct mwReturnCodeDesc, 1); if (code & ERR_FAILURE) rcDesc->type = mwReturnCodeError; else rcDesc->type = mwReturnCodeInfo; rcDesc->codeString = g_strdup(err_to_str(code)); rcDesc->name = mwError(code); rcDesc->description = mwErrorDesc(code); return rcDesc; }
context_t* context_create(cl_device_type dev_type) { context_t* context = malloc(sizeof(*context)); if (context != NULL) { int ret = 0; cl_int err; context->dev_type = dev_type; err = clGetPlatformIDs(0, NULL, &context->plat_count); if (err == CL_SUCCESS) { #ifdef DEBUG printf("platforms count: %d\n", context->plat_count); #endif context->plat = malloc(sizeof(*context->plat) * context->plat_count); err = clGetPlatformIDs(context->plat_count, context->plat, NULL); if (err == CL_SUCCESS) { context->dev_on_plat = malloc(sizeof(*context->dev_on_plat) * context->plat_count); context->dev = malloc(sizeof(*context->dev) * context->plat_count); // context->dev_prop = malloc(sizeof(*context->dev_prop) * context->plat_count); context->contexts = malloc(sizeof(*contexts) * context->plat_count); context->cmd = malloc(sizeof(*context->cmd) * context->plat_count); int p; for (p = 0; p < context->plat_count; p++) { err = clGetDeviceIDs(context->plat[p], context->dev_type, 0, NULL, &context->dev_on_plat[p]); if (err == CL_SUCCESS) { #ifdef DEBUG printf("platform: %d\t devices: %d\n", p, context->dev_on_plat[p]); #endif context->total_dev_count += context->dev_on_plat[p]; context->dev[p] = malloc(sizeof(**context->dev) * context->dev_on_plat[p]); // context->dev_prop[p] = malloc(sizeof(**context->dev_prop) * context->dev_on_plat[p]); context->contexts[p] = malloc(sizeof(**context->contexts) * context->dev_on_plat[p]); context->cmd[p] = malloc(sizeof(**context->cmd) * context->dev_on_plat[p]); err = clGetDeviceIDs(context->plat[p], context->dev_type, context->dev_on_plat[p], context->dev[p], NULL); if (err == CL_SUCCESS) { cl_context_properties properties[3] = { CL_CONTEXT_PLATFORM, (cl_context_properties) context->plat[p], 0 }; int d; for (d = 0; d < context->dev_on_plat[p]; d++) { // !!! добавить обработку ошибок !!! // clGetDeviceInfo(devices[i][j], // CL_DEVICE_MAX_PARAMETER_SIZE, // sizeof(devices_prop[i][j].max_param_size), // &devices_prop[i][j].max_param_size, // NULL); // !!! на базе считанных параметров необходимо вычислить коэффициент от 1 до 100 !!! // !!! пропорционально данному коэффициенту модули будут разбивать данные для параллельного вычисления !!! #ifdef DEBUG printf("plat: %d\t dev: %d\n", p, d); #endif context->contexts[p][d] = clCreateContext(properties, 1, &context->dev[p][d], NULL, NULL, &err); if (err == CL_SUCCESS) { context->cmd[p][d] = clCreateCommandQueue(context->contexts[p][d], context->dev[p][d], CL_QUEUE_PROFILING_ENABLE, &err); if (err != CL_SUCCESS) { #ifdef DEBUG printf("clCreateCommandQueue [ %s ]\n", err_to_str(err)); #endif ret = 6; break; } } else { #ifdef DEBUG printf("clCreateContext [ %s ]\n", err_to_str(err)); #endif ret = 5; break; } } } else { #ifdef DEBUG printf("clGetDeviceIDs [ %s ]\n", err_to_str(err)); #endif ret = 4; } } else { #ifdef DEBUG printf("clGetDeviceIDs [ %s ]\n", err_to_str(err)); #endif ret = 3; } } } else { #ifdef DEBUG printf("clGetPlatformIDs [ %s ]\n", err_to_str(err)); #endif ret = 2; } } else { #ifdef DEBUG printf("clGetPlatformIDs [ %s ]\n", err_to_str(err)); #endif ret = 1; } if (ret != 0) { context_clear(context); } } return context; }
char* mwError(guint32 code) { const char *m; switch(code) { /* 8.3.1.1 General error/success codes */ CASE(ERR_SUCCESS, LPGEN("Success")); CASE(ERR_FAILURE, LPGEN("General failure")); CASE(ERR_REQUEST_DELAY, LPGEN("Request delayed")); CASE(ERR_REQUEST_INVALID, LPGEN("Request is invalid")); CASE(ERR_NOT_LOGGED_IN, LPGEN("Not logged in")); CASE(ERR_NOT_AUTHORIZED, LPGEN("Not authorized")); CASE(ERR_ABORT, LPGEN("Operation aborted")); CASE(ERR_NO_ELEMENT, LPGEN("No element")); CASE(ERR_NO_USER, LPGEN("User is not online")); CASE(ERR_BAD_DATA, LPGEN("Invalid data")); CASE(ERR_NOT_IMPLEMENTED, LPGEN("Not implemented")); CASE(ERR_UNKNOWN_ERROR, LPGEN("Unknown error")); CASE(ERR_STARVING, LPGEN("Not enough resources")); CASE(ERR_CHANNEL_NO_SUPPORT, LPGEN("Requested channel is not supported")); CASE(ERR_CHANNEL_EXISTS, LPGEN("Requested channel already exists")); CASE(ERR_SERVICE_NO_SUPPORT, LPGEN("Requested service is not supported")); CASE(ERR_PROTOCOL_NO_SUPPORT, LPGEN("Requested protocol is not supported")); CASE(ERR_PROTOCOL_NO_SUPPORT2, LPGEN("Requested protocol is not supported")); CASE(ERR_VERSION_NO_SUPPORT, LPGEN("Version is not supported")); CASE(ERR_USER_SKETCHY, LPGEN("User is invalid or not trusted")); CASE(ERR_ALREADY_INITIALIZED, LPGEN("Already initialized")); CASE(ERR_NOT_OWNER, LPGEN("Not an owner")); CASE(ERR_TOKEN_INVALID, LPGEN("Invalid token")); CASE(ERR_TOKEN_EXPIRED, LPGEN("Token expired")); CASE(ERR_TOKEN_IP_MISMATCH, LPGEN("Token mismatch")); CASE(ERR_PORT_IN_USE, LPGEN("Port in use")); CASE(ERR_NETWORK_DEAD, LPGEN("Network error")); CASE(ERR_NO_MASTER_CHANNEL, LPGEN("Master channel error")); CASE(ERR_ALREADY_SUBSCRIBED, LPGEN("Already subscribed")); CASE(ERR_NOT_SUBSCRIBED, LPGEN("Not subscribed")); CASE(ERR_ENCRYPT_NO_SUPPORT, LPGEN("Encryption method not supported")); CASE(ERR_ENCRYPT_UNINITIALIZED, LPGEN("Encryption not initialized")); CASE(ERR_ENCRYPT_UNACCEPTABLE, LPGEN("Encryption too low")); CASE(ERR_ENCRYPT_INVALID, LPGEN("Invalid encrypted data")); CASE(ERR_NO_COMMON_ENCRYPT, LPGEN("No common encryption method")); CASE(ERR_CHANNEL_DESTROYED, LPGEN("Channel destroyed")); CASE(ERR_CHANNEL_REDIRECTED, LPGEN("Channel redirected")); CASE(ERR_INCORRECT_ENTRY, LPGEN("Incorrect entry")); /* 8.3.1.2 Connection/disconnection errors */ CASE(VERSION_MISMATCH, LPGEN("Version mismatch")); CASE(INSUF_BUFFER, LPGEN("Not enough buffers memory")); CASE(NOT_IN_USE, LPGEN("Not in use")); CASE(INSUF_SOCKET, LPGEN("Not enough sockets")); CASE(HARDWARE_ERROR, LPGEN("Hardware error")); CASE(NETWORK_DOWN, LPGEN("Network error")); CASE(HOST_DOWN, LPGEN("Host error")); CASE(HOST_UNREACHABLE, LPGEN("Host unreachable")); CASE(TCPIP_ERROR, LPGEN("Internet protocol error")); CASE(FAT_MESSAGE, LPGEN("Message is too large")); CASE(PROXY_ERROR, LPGEN("Proxy error")); CASE(SERVER_FULL, LPGEN("Server full")); CASE(SERVER_NORESPOND, LPGEN("Server not responding")); CASE(CANT_CONNECT, LPGEN("Connection error")); CASE(USER_REMOVED, LPGEN("User removed")); CASE(PROTOCOL_ERROR, LPGEN("Sametime protocol error")); CASE(USER_RESTRICTED, LPGEN("User restricted")); CASE(INCORRECT_LOGIN, LPGEN("Incorrect Username/Password")); CASE(ENCRYPT_MISMATCH, LPGEN("Encryption mismatch")); CASE(USER_UNREGISTERED, LPGEN("User unregistered")); CASE(VERIFICATION_DOWN, LPGEN("Login verification down or unavailable")); CASE(USER_TOO_IDLE, LPGEN("User too idle")); CASE(GUEST_IN_USE, LPGEN("The guest name is currently being used")); CASE(USER_EXISTS, LPGEN("User exists")); CASE(USER_RE_LOGIN, LPGEN("User relogin")); CASE(BAD_NAME, LPGEN("Bad name")); CASE(REG_MODE_NS, LPGEN("Registration error")); CASE(WRONG_USER_PRIV, LPGEN("Privilege error")); CASE(NEED_EMAIL, LPGEN("Need email")); CASE(DNS_ERROR, LPGEN("DNS error")); CASE(DNS_FATAL_ERROR, LPGEN("DNS fatal error")); CASE(DNS_NOT_FOUND, LPGEN("DNS not found")); CASE(CONNECTION_BROKEN, LPGEN("Connection broken")); CASE(CONNECTION_ABORTED, LPGEN("Connection aborted")); CASE(CONNECTION_REFUSED, LPGEN("Connection refused")); CASE(CONNECTION_RESET, LPGEN("Connection reset")); CASE(CONNECTION_TIMED, LPGEN("Connection timed out")); CASE(CONNECTION_CLOSED, LPGEN("Connection closed")); CASE(MULTI_SERVER_LOGIN, LPGEN("Login to two different servers concurrently (1)")); CASE(MULTI_SERVER_LOGIN2, LPGEN("Login to two different servers concurrently (2)")); CASE(MULTI_LOGIN_COMP, LPGEN("Already logged on, disconnected")); CASE(MUTLI_LOGIN_ALREADY, LPGEN("Already logged on")); CASE(SERVER_BROKEN, LPGEN("Server misconfiguration")); CASE(SERVER_PATH_OLD, LPGEN("Server needs upgrade")); CASE(APPLET_LOGOUT, LPGEN("Applet Logout")); /* 8.3.1.3 Client error codes */ CASE(ERR_CLIENT_USER_GONE, LPGEN("User is not online")); CASE(ERR_CLIENT_USER_DND, LPGEN("User is in Do Not Disturb mode")); CASE(ERR_CLIENT_USER_ELSEWHERE, LPGEN("Already logged in elsewhere")); /* 8.3.1.4 IM error codes */ CASE(ERR_IM_COULDNT_REGISTER, LPGEN("Cannot register a reserved type")); CASE(ERR_IM_ALREADY_REGISTERED, LPGEN("Requested type is already registered")); CASE(ERR_IM_NOT_REGISTERED, LPGEN("Requested type is not registered")); /* 8.3.1.5 Resolve error codes */ CASE(ERR_RESOLVE_NOTCOMPLETED, LPGEN("Resolve not completed")); CASE(ERR_RESOLVE_NAMENOTUNIQUE, LPGEN("Resolve name not unique")); CASE(ERR_RESOLVE_NAMENOTRESOLVABLE, LPGEN("Resolve name not resolvable")); default: m = err_to_str(code); } return g_strdup(m); }