/** * Create endpoints and connection for DSP * @return MCAPI_SUCCESS/Error Code */ mcapi_status_t dsp_initialize(void) { mcapi_status_t status = MCAPI_ERR_GENERAL; /** * Create end-point for data and command transfer */ dsp_command_endpoint = mcapi_endpoint_create(PORT_COMMAND, &status); #ifdef DEBUG_INFO if (MCAPI_SUCCESS != status) { fprintf(stdout, "[%s] %d status: %d mcapi_endpoint_create failure\n", __FILE__, __LINE__, status); exit(1); } #endif dsp_data_endpoint = mcapi_endpoint_create(PORT_DATA, &status); #ifdef DEBUG_INFO if (MCAPI_SUCCESS != status) { fprintf(stdout, "[%s] %d status: %d mcapi_endpoint_create failure\n", __FILE__, __LINE__, status); exit(1); } #endif dsp_data_send_endpoint = mcapi_endpoint_create(PORT_DATA_RECV, &status); #ifdef DEBUG_INFO if (MCAPI_SUCCESS != status) { fprintf(stdout, "[%s] %d status: %d mcapi_endpoint_create failure\n", __FILE__, __LINE__, status); exit(1); } #endif /** * Get the remote endpoints for communication */ remote_data_recv_endpoint = mcapi_endpoint_get(DOMAIN, NODE_CORE_0, PORT_DATA_RECV, MCAPI_TIMEOUT_INFINITE, &status); #ifdef DEBUG_INFO if (MCAPI_SUCCESS != status) { fprintf(stdout, "[%s] %d status: %d mcapi_endpoint_get failure\n", __FILE__, __LINE__, status); exit(1); } #endif dsp_data_endpoint = dsp_data_send_endpoint; dsp_command_endpoint = dsp_data_send_endpoint; return status; }
int main(int argc, char *argv[]) { //the endpoints used in message-oriented communication mcapi_endpoint_t red_msg_point; mcapi_endpoint_t yellow_msg_point; mcapi_endpoint_t green_msg_point; //the endpoints used in channel-oriented communication mcapi_endpoint_t yellow_sin_chan; mcapi_endpoint_t yellow_cos_chan; mcapi_endpoint_t yellow_pkt_chan; //status message received in almost all MCAPI-calls mcapi_status_t status; //info-struct received in initialization mcapi_info_t info; //buffer for incoming messages char recv_buf[MAX_MSG_LEN]; //the status code converted to string char status_msg[MCAPI_MAX_STATUS_MSG_LEN]; //size parameter required in some calls size_t size = 1; //an iterator used in loops unsigned int i = 0; //request handle is used to operate wait-calls mcapi_request_t request; //a second request handle! just so that we see it works :) mcapi_request_t request2; //sandles used in channel-messaging mcapi_sclchan_recv_hndl_t sin_handle; mcapi_sclchan_recv_hndl_t cos_handle; mcapi_pktchan_send_hndl_t pkt_handle; //how many scalars we are expecting char count = 0; //buffer of data sent in messages unsigned char* send_buf; printf(COLOR "here\n"); //We are yellow! initialize accordingly mcapi_initialize( THE_DOMAIN, YELLOW_NODE, 0, 0, &info, &status ); check( MCAPI_SUCCESS, status ); //create our side of messaging yellow_msg_point = mcapi_endpoint_create( YELLOW_MSG, &status ); check( MCAPI_SUCCESS, status ); //obtain the red message point red_msg_point = mcapi_endpoint_get( THE_DOMAIN, RED_NODE, RED_MSG, TIMEOUT, &status ); check( MCAPI_SUCCESS, status ); printf(COLOR "start-up messaging\n"); //wait for the amount to come mcapi_msg_recv( yellow_msg_point, recv_buf, MAX_MSG_LEN, &size, &status ); check( MCAPI_SUCCESS, status ); //read the count from first byte count = recv_buf[0]; //surprise! this process reserves the buffer with malloc send_buf = (char*)malloc(count*2); //send ack send_buf[0] = 'a'; mcapi_msg_send( yellow_msg_point, red_msg_point, send_buf, 1, 0, &status ); check( MCAPI_SUCCESS, status ); printf(COLOR "start-up messaged with %u bytes. expecting %u scalars\n", size, count ); //open our channel endpoint to sin yellow_sin_chan = mcapi_endpoint_create( YELLOW_SIN, &status ); check( MCAPI_SUCCESS, status ); //open our channel endpoint to cos yellow_cos_chan = mcapi_endpoint_create( YELLOW_COS, &status ); check( MCAPI_SUCCESS, status ); //open our ends, let senders form connection mcapi_sclchan_recv_open_i( &sin_handle, yellow_sin_chan, &request, &status ); check( MCAPI_PENDING, status ); mcapi_sclchan_recv_open_i( &cos_handle, yellow_cos_chan, &request2, &status ); check( MCAPI_PENDING, status ); //wait for it to happen mcapi_wait( &request, &size, TIMEOUT, &status ); check( MCAPI_SUCCESS, status ); mcapi_wait( &request2, &size, TIMEOUT, &status ); check( MCAPI_SUCCESS, status ); printf(COLOR "beginning the receive value\n"); for ( i = 0; i < 15000; ++i ) { //an iterator used in loops unsigned int j = 0; //start to receveive stuff //i+=2 because our values are two bytes while buf is one byte for ( j = 0; j < count; ++j ) { //receive cos scalar short cval = mcapi_sclchan_recv_uint16( cos_handle, &status ); check( MCAPI_SUCCESS, status ); //receive sin scalar short sval = mcapi_sclchan_recv_uint16( sin_handle, &status ); check( MCAPI_SUCCESS, status ); //addition short sumval = sval + cval; //put to buf send_buf[j*2] = sumval; send_buf[j*2+1] = sumval >> 8; //printf( COLOR "%hX %hhX %hhX\n", sumval, send_buf[j*2], //send_buf[j*2+1] ); } } printf(COLOR "receiving done, closing scalar channels\n"); //close our ends mcapi_sclchan_recv_close_i( sin_handle, &request, &status ); check( MCAPI_PENDING, status ); mcapi_sclchan_recv_close_i( cos_handle, &request2, &status ); check( MCAPI_PENDING, status ); //wait for it to happen mcapi_wait( &request, &size, TIMEOUT, &status ); check( MCAPI_SUCCESS, status ); mcapi_wait( &request2, &size, TIMEOUT, &status ); check( MCAPI_SUCCESS, status ); printf(COLOR "closed, informing green\n"); //obtain their endpoint green_msg_point = mcapi_endpoint_get( THE_DOMAIN, GREEN_NODE, GREEN_MSG, TIMEOUT, &status ); check( MCAPI_SUCCESS, status ); //send the message mcapi_msg_send( yellow_msg_point, green_msg_point, send_buf, 1, 0, &status ); check( MCAPI_SUCCESS, status ); printf(COLOR "informed, opening packet channel\n"); //open our channel endpoint to green yellow_pkt_chan = mcapi_endpoint_create( YELLOW_PKT, &status ); check( MCAPI_SUCCESS, status ); //open our end, let receiver form connection mcapi_pktchan_send_open_i( &pkt_handle, yellow_pkt_chan, &request, &status ); check( MCAPI_PENDING, status ); //wait for it to happen mcapi_wait( &request, &size, TIMEOUT, &status ); check( MCAPI_SUCCESS, status ); //now send printf(COLOR "sending the packet\n"); mcapi_pktchan_send( pkt_handle, send_buf, count, &status ); //and now close printf(COLOR "sent the packet, closing\n"); mcapi_pktchan_send_close_i( pkt_handle, &request, &status ); check( MCAPI_PENDING, status ); mcapi_wait( &request, &size, TIMEOUT, &status ); check( MCAPI_SUCCESS, status ); printf(COLOR "closed, shutdown\n"); //free buf free( send_buf ); //shut-down mcapi_finalize( &status ); check( MCAPI_SUCCESS, status ); return EXIT_SUCCESS; }
int main() { //status message received in almost all MCAPI-calls mcapi_status_t status; //info-struct received in initialization mcapi_info_t info; //the status code converted to string char status_msg[MCAPI_MAX_STATUS_MSG_LEN]; //an iterator used in loops unsigned int i = 0; //request handle is used to operate wait-calls mcapi_request_t request; //size parameter required in some calls size_t size = 1; //send-handle used in channel-messaging mcapi_pktchan_send_hndl_t handy; //a separate receive buffer used for messages char recv_msg[MAX_MSG_LEN]; //get our stuff here. tip: if signed were used, it bastardized the values unsigned char* recv_buf; //the endpoints used in channel-oriented communication mcapi_endpoint_t green_chan; mcapi_endpoint_t yellow_chan; mcapi_endpoint_t green_msg_point; printf( COLOR "here\n"); //we are the green mcapi_initialize( THE_DOMAIN, GREEN_NODE, 0, 0, &info, &status ); check( MCAPI_SUCCESS, status ); //create our message endpoint green_msg_point = mcapi_endpoint_create( GREEN_MSG, &status ); check( MCAPI_SUCCESS, status ); //wait for the start signal mcapi_msg_recv(green_msg_point, recv_msg, MAX_MSG_LEN, &size, &status ); check( MCAPI_SUCCESS, status ); printf(COLOR "signal received, starting to connect & open\n"); //create our channel message endpoint green_chan = mcapi_endpoint_create( GREEN_PKT, &status ); check( MCAPI_SUCCESS, status ); //get their channel message endpoint yellow_chan = mcapi_endpoint_get( THE_DOMAIN, YELLOW_NODE, YELLOW_PKT, TIMEOUT, &status ); check( MCAPI_SUCCESS, status ); //form the channel mcapi_pktchan_connect_i( yellow_chan, green_chan, &request, &status ); check( MCAPI_PENDING, status ); //wait for it to happen mcapi_wait( &request, &size, TIMEOUT, &status ); check( MCAPI_SUCCESS, status ); //open our end mcapi_pktchan_recv_open_i( &handy, green_chan, &request, &status ); check( MCAPI_PENDING, status ); //wait for it to happen mcapi_wait( &request, &size, TIMEOUT, &status ); check( MCAPI_SUCCESS, status ); printf(COLOR "beginning the receive\n"); //start to receive our stuff mcapi_pktchan_recv( handy, (void*)&recv_buf, &size, &status ); check( MCAPI_SUCCESS, status ); printf(COLOR "retrieval done, closing\n"); //close our end mcapi_pktchan_recv_close_i( handy, &request, &status ); check( MCAPI_PENDING, status ); //wait for it to happen mcapi_wait( &request, &size, TIMEOUT, &status ); check( MCAPI_SUCCESS, status ); printf(COLOR "closed, go over the values\n"); //go through that stuff //i+=2 because our values are two bytes while buf is one byte for ( i = 0; i < size; i+=2 ) { //reconstruct the short short sumval = recv_buf[i+1] << 8 | recv_buf[i]; //printf( COLOR "%hX %hhX %hhX\n", sumval, recv_buf[i], recv_buf[i+1] ); } printf(COLOR "buffer release and shut down\n"); //release mcapi_pktchan_release( recv_buf, &status ); check( MCAPI_SUCCESS, status ); //finalize at the end, regardless of which process we are mcapi_finalize( &status ); check( MCAPI_SUCCESS, status ); return EXIT_SUCCESS; }
/** * Creates local end-points on GPP and gets remote DSP end-points * * @return MCAPI_SUCCESS/error */ mcapi_status_t initialize_comms(void) { mcapi_status_t status = MCAPI_ERR_GENERAL; /** * Create local end-points for communication */ #ifdef DEBUG_INFO printf("[CORE A]: Initializing communication\n"); #endif command_endpoint = mcapi_endpoint_create(PORT_COMMAND, &status); #ifdef DEBUG_INFO if (MCAPI_SUCCESS != status) { fprintf(stdout, "[%s] %d status: %d mcapi_endpoint_create failure\n", __FILE__, __LINE__, status); exit(1); } #endif data_endpoint = mcapi_endpoint_create(PORT_DATA, &status); #ifdef DEBUG_INFO if (MCAPI_SUCCESS != status) { fprintf(stdout, "[%s] %d status: %d mcapi_endpoint_create failure\n", __FILE__, __LINE__, status); exit(1); } #endif data_recv_endpoint = mcapi_endpoint_create(PORT_DATA_RECV, &status); #ifdef DEBUG_INFO if (MCAPI_SUCCESS != status) { fprintf(stdout, "[%s] %d status: %d mcapi_endpoint_create failure\n", __FILE__, __LINE__, status); exit(1); } #endif /** * Get the remote end-points for communication */ remote_command_endpoint = mcapi_endpoint_get(DOMAIN, NODE_CORE_1, PORT_COMMAND, MCAPI_TIMEOUT_INFINITE, &status); #ifdef DEBUG_INFO if (MCAPI_SUCCESS != status) { fprintf(stdout, "[%s] %d status: %d mcapi_endpoint_get failure\n", __FILE__, __LINE__, status); exit(1); } #endif remote_data_endpoint = mcapi_endpoint_get(DOMAIN, NODE_CORE_1, PORT_DATA, MCAPI_TIMEOUT_INFINITE, &status); #ifdef DEBUG_INFO if (MCAPI_SUCCESS != status) { fprintf(stdout, "[%s] %d status: %d mcapi_endpoint_get failure\n", __FILE__, __LINE__, status); exit(1); } #endif remote_data_recv_endpoint = mcapi_endpoint_get(DOMAIN, NODE_CORE_1, PORT_DATA_RECV, MCAPI_TIMEOUT_INFINITE, &status); #ifdef DEBUG_INFO if (MCAPI_SUCCESS != status) { fprintf(stdout, "[%s] %d status: %d mcapi_endpoint_get failure\n", __FILE__, __LINE__, status); exit(1); } #endif data_endpoint = data_recv_endpoint; command_endpoint = data_recv_endpoint ; remote_data_endpoint = remote_data_recv_endpoint; remote_command_endpoint = remote_data_recv_endpoint; return status; }
void *sender(void* data) { char buffer[NUM_MSGS]; int count = 0; mca_status_t status; int i; mcapi_param_t parms; mcapi_info_t version; mcapi_priority_t priority = 1; mcapi_endpoint_t remote_recv_endpt; /* create a node */ mcapi_initialize(DOMAIN,NODE,NULL,&parms,&version,&status); if (status != MCAPI_SUCCESS) { fprintf(stderr,"\nERROR: Failed to initialize: %s\n",mcapi_display_status(status,status_buff,sizeof(status_buff))); WRONG; } /* make send endpoint */ send_endpt = mcapi_endpoint_create(0,&status); if (status != MCAPI_SUCCESS) { fprintf(stderr,"\nERROR: Failed to create send endpoint: %s\n",mcapi_display_status(status,status_buff,sizeof(status_buff))); WRONG; } /* get a recv endpoint */ remote_recv_endpt = mcapi_endpoint_get(DOMAIN,NODE+1,1,MCA_INFINITE,&status); if (status != MCAPI_SUCCESS) { fprintf(stderr,"\nERROR: Failed to get receive endpoint: %s\n",mcapi_display_status(status,status_buff,sizeof(status_buff))); WRONG; } /* do the sends */ for (count = 0; count < NUM_MSGS; count++) { sprintf(buffer,"Sending: %d",count); printf("Sending: [%s]\n",buffer); mcapi_msg_send(send_endpt, remote_recv_endpt, buffer, strlen(buffer), priority, &status); if ((status != MCAPI_SUCCESS) && (TIMEOUT)) { /* yield and then retry */ for (i = 0; i < TIMEOUT; i++) { if (status == MCAPI_ERR_MEM_LIMIT) { fprintf(stderr,"WARNING: Send failed: reason:%s send_count:%d. Will yield and re-try.\n",mcapi_display_status(status,status_buff,sizeof(status_buff)),count); sched_yield(); mcapi_msg_send(send_endpt, remote_recv_endpt, buffer, strlen(buffer), priority, &status); } if (status == MCAPI_SUCCESS) { break; } } } if (status != MCAPI_SUCCESS) { fprintf(stderr,"\nFAIL: Send failed: reason:%s send_count:%d\n",mcapi_display_status(status,status_buff,sizeof(status_buff)),count); WRONG; } } /* finalize */ mcapi_finalize(&status); if (status != MCAPI_SUCCESS) { fprintf(stderr,"\nFAIL: Failed to finalize: %s\n",mcapi_display_status(status,status_buff,sizeof(status_buff))); WRONG; } return NULL; }
/***************************************************************************** * setup_echo_endpoints *****************************************************************************/ int setup_echo_endpoints(int task_id) { mcapi_status_t status; int local_send_port = 0; int local_recv_port = 1; int next_node = (task_id == num_tasks - 1) ? 0 + th_get_node_offset() : task_id + 1 + th_get_node_offset(); int next_recv_port = 1; mcapi_info_t version; mcapi_param_t parms; /* TODO -- this needs to be cleaned up */ /* figure out how many cores we have, then split the tasks up evenly among the cores */ #if (WITH_AFFINITY != 0) int i; int num_cores = 2; int tasks_per_core = num_tasks/num_cores; int core = 0; for (i = 0; i < num_tasks; i+=tasks_per_core) { if ((i <= task_id) && ((i + tasks_per_core) >= task_id )) { th_log("[TC_ECHO] -- setting task_id(%i) affinity to core(%i)\n",task_id,core); th_set_affinity(core); break; } core++; } #endif /* initialize */ //mca_set_debug_level(1); mcapi_initialize(CONKER_TESTCASE_DOMAIN, task_id + th_get_node_offset(), NULL,&parms,&version,&status); if (status != MCAPI_SUCCESS) { th_log_error("Task id %d failed to initialize: %s\n", task_id, mcapi_display_status(status,status_buff,sizeof(status_buff))); return -1; } /* create local_send endpoint */ th_log_info("[TC_ECHO] -- creating local send endpoint node=%d, port=%d\n", task_id + th_get_node_offset(), local_send_port); local_endpts[task_id].endpts[WRITE_IDX] = mcapi_endpoint_create(local_send_port, &status); if (status != MCAPI_SUCCESS) { th_log_error("Task id %d failed to create local send endpoint: %s\n", task_id, mcapi_display_status(status,status_buff,sizeof(status_buff))); return -1; } /* create local_recv endpoint */ th_log_info("[TC_ECHO] -- creating local recv endpoint node=%d, port=%d\n", task_id + th_get_node_offset(), local_recv_port); local_endpts[task_id].endpts[READ_IDX] = mcapi_endpoint_create(local_recv_port, &status); if (status != MCAPI_SUCCESS) { th_log_error("Task id %d failed to create local receive endpoint: %s\n", task_id, mcapi_display_status(status,status_buff,sizeof(status_buff))); return -1; } /* get the endpoint to send to */ th_log_info("[TC_ECHO] -- get next recv endpt, node=%d, next_node=%d, next_recv_port=%d\n", task_id, next_node, next_recv_port); remote_endpts[task_id] = mcapi_endpoint_get(CONKER_TESTCASE_DOMAIN, next_node, next_recv_port, TIMEOUT,&status); if (status != MCAPI_SUCCESS) { th_log_error("Task id %d failed to get next recv endpoint: %s\n", task_id, mcapi_display_status(status,status_buff,sizeof(status_buff))); return -1; } return 0; }