int main() { xps_timer_t timer; int time_create, time_start, time_stop; // ************************************************************************************* extern unsigned char intermediate[]; extern unsigned int dct_handle_offset; unsigned int dct_handle = (dct_handle_offset) + (unsigned int)(&intermediate); extern unsigned int idct_handle_offset; unsigned int idct_handle = (idct_handle_offset) + (unsigned int)(&intermediate); // ************************************************************************************* // Thread attribute structures Huint sta[NUM_THREADS]; void* retval[NUM_THREADS]; hthread_t tid[NUM_THREADS]; hthread_attr_t attr[NUM_THREADS]; targ_t targ[NUM_THREADS]; int my_dct_matrix[BLOCK_SIZE][BLOCK_SIZE] = { {23170, 23170, 23170, 23170, 23170, 23170, 23170, 23170 }, {32138, 27246, 18205, 6393, -6393, -18205, -27246, -32138 }, {30274, 12540, -12540, -30274, -30274, -12540, 12540, 30274 }, {27246, -6393, -32138, -18205, 18205, 32138, 6393, -27246 }, {23170, -23170, -23170, 23170, 23170, -23170, -23170, 23170 }, {18205, -32138, 6393, 27246, -27246, -6393, 32138, -18205 }, {12540, -30274, 30274, -12540, -12540, 30274, -30274, 12540 }, {6393 , -18205, 27246, -32138, 32138, -27246, 18205, -6393 } }; int my_dct_matrix_trans[BLOCK_SIZE][BLOCK_SIZE] = { {0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0} }; int my_temp[BLOCK_SIZE][BLOCK_SIZE]; int my_input[BLOCK_SIZE][BLOCK_SIZE]; int my_intermediate_dct[BLOCK_SIZE][BLOCK_SIZE]; int my_intermediate_idct[BLOCK_SIZE][BLOCK_SIZE]; int my_output[BLOCK_SIZE][BLOCK_SIZE]; int my_idct_output[BLOCK_SIZE][BLOCK_SIZE]; int my_scale_factor = 16; // Create timer xps_timer_create(&timer, (int*)0x20400000); // Start timer xps_timer_start(&timer); int i,j; #ifdef USE_MB_THREAD printf("Using heterogeneous MB threads\r\n"); printf("\tCode start address = 0x%08x\n", (unsigned int)&intermediate); #else printf("Using native PPC threads\r\n"); #endif for (j = 0; j < NUM_THREADS; j++) { // Initialize the attributes for the threads hthread_attr_init( &attr[j] ); hthread_attr_sethardware( &attr[j], (void*)base_array[j] ); } // Calculate transpose of dct_matrix initialize_dct_matrix(my_dct_matrix, my_dct_matrix_trans); // Initialize input for (i = 0; i < BLOCK_SIZE; i++) { for (j = 0; j < BLOCK_SIZE; j++) { my_input[i][j] = i+j; } } // Fill in thread arguments for an initial DCT run targ[0].scale_factor = my_scale_factor; targ[0].input = my_input; targ[0].intermediate = my_intermediate_dct; targ[0].output = my_temp; targ[0].coeff_matrix = my_dct_matrix; targ[0].coeff_matrix_trans = my_dct_matrix_trans; dct_thread(&targ[0]); printf("\r\nOriginal Input:\r\n"); print_matrix(my_input); printf("\r\nOriginal DCT:\r\n"); print_matrix(my_temp); printf("**************************************************\r\n"); // Fill in thread arguments targ[0].scale_factor = my_scale_factor; targ[0].input = my_input; targ[0].intermediate = my_intermediate_dct; targ[0].output = my_output; targ[0].coeff_matrix = my_dct_matrix; targ[0].coeff_matrix_trans = my_dct_matrix_trans; targ[1].scale_factor = my_scale_factor; targ[1].input = my_temp; targ[1].intermediate = my_intermediate_idct; targ[1].output = my_idct_output; targ[1].coeff_matrix = my_dct_matrix; targ[1].coeff_matrix_trans = my_dct_matrix_trans; // Start timing thread create time_create = xps_timer_read_counter(&timer); // Peform DCT //dct_thread(&targ); // Use a thread #ifdef USE_MB_THREAD sta[0] = hthread_create( &tid[0], &attr[0], (void*)dct_handle, (void*)&targ[0] ); #else sta[0] = hthread_create( &tid[0], NULL, dct_thread, (void*)&targ[0]); #endif // Peform IDCT //idct_thread(&targ); // Use a thread #ifdef USE_MB_THREAD sta[1] = hthread_create( &tid[1], &attr[1], (void*)idct_handle, (void*)&targ[1] ); #else sta[1] = hthread_create( &tid[1], NULL, idct_thread, (void*)&targ[1]); #endif // Allow created threads to begin running and start timer time_start = xps_timer_read_counter(&timer); // Wait for threads to complete hthread_join(tid[0],&retval[0]); hthread_join(tid[1],&retval[1]); // Stop timer time_stop = xps_timer_read_counter(&timer); printf("\r\nDCT (retval = 0x%08x):\r\n",(unsigned int)retval[0]); print_matrix(my_output); printf("\r\nIDCT (retval = 0x%08x):\r\n",(unsigned int)retval[1]); print_matrix(my_idct_output); printf("*********************************\n"); printf("Create time = %u\n",time_create); printf("Start time = %u\n",time_start); printf("Stop time = %u\n",time_stop); printf("*********************************\n"); printf("Creation time (|Start - Create|) = %u\n",time_start - time_create); printf("Elapsed time (|Stop - Start|) = %u\n",time_stop - time_start); printf("Total time (|Create - Stop|) = %u\n",time_stop - time_create); return 0; }
int main( int argc, char *argv[] ) { if (NUM_THREADS > 2){ printf("CANNOT USE MORE THAN (2) HETEROGENEOUS THREADS!!!!\r\n"); return (-1); } // Timer variables xps_timer_t timer; int time_create, time_start, time_stop; // Mutex hthread_mutex_t * mutex = (hthread_mutex_t*)malloc( sizeof(hthread_mutex_t) ); hthread_mutex_init( mutex, NULL ); // Thread attribute structures Huint sta[NUM_THREADS]; void* retval[NUM_THREADS]; hthread_t tid[NUM_THREADS]; hthread_attr_t attr[NUM_THREADS]; targ_t thread_arg[NUM_THREADS]; // Setup Cache XCache_EnableICache(0xc0000801); // Create timer xps_timer_create(&timer, (int*)0x20400000); // Start timer xps_timer_start(&timer); // ************************************************************************************* extern unsigned char intermediate[]; extern unsigned int blink_handle_offset; unsigned int blink_handle = (blink_handle_offset) + (unsigned int)(&intermediate); // ************************************************************************************* int j = 0; printf("Code start address = 0x%08x\n", (unsigned int)&intermediate); for (j = 0; j < NUM_THREADS; j++) { // Initialize the attributes for the threads hthread_attr_init( &attr[j] ); hthread_attr_sethardware( &attr[j], (void*)base_array[j] ); } int num_ops = 0; for( num_ops = 0; num_ops < 1; num_ops = num_ops + 1) { printf("******* Round %d ********\n",num_ops); #ifdef USE_MB_THREAD printf("**** MB-based Threads ****\n"); #else printf("**** PPC-based Threads ****\n"); #endif // Initialize thread arguments for ( j= 0; j < NUM_THREADS; j++) { thread_arg[j].arg = 1 << ((j + 1)); thread_arg[j].mutex = mutex; } time_create = xps_timer_read_counter(&timer); // Create threads for (j = 0; j < NUM_THREADS; j++) { // Create the blink thread #ifdef USE_MB_THREAD // Create MB Thread sta[j] = hthread_create( &tid[j], &attr[j], (void*)blink_handle, (void*)(&thread_arg[j]) ); //printf( "Started MB Thread (TID = %d) \n", tid[j]); #else // Create SW Thread sta[j] = hthread_create( &tid[j], NULL, blink_thread, (void*)(&thread_arg[j]) ); //printf( "Started SW Thread (TID = %d) \n", tid[j]); #endif } // Allow created threads to begin running and start timer time_start = xps_timer_read_counter(&timer); printf("Waiting for threads...\n"); // Join on all threads for (j = 0; j < NUM_THREADS; j++) { hthread_join( tid[j], &retval[j] ); } // Grab stop time time_stop = xps_timer_read_counter(&timer); // Print out status for (j = 0; j < NUM_THREADS; j++) { printf("TID[%d] = 0x%08x, status = 0x%08x, retval = 0x%08x\n",j,tid[j],sta[j],(unsigned int)retval[j]); } printf("*********************************\n"); printf("Create time = %u\n",time_create); printf("Start time = %u\n",time_start); printf("Stop time = %u\n",time_stop); printf("*********************************\n"); printf("Creation time (|Start - Create|) = %u\n",time_start - time_create); printf("Elapsed time (|Stop - Start|) = %u\n",time_stop - time_start); } hthread_mutex_destroy( mutex ); free( mutex ); // Clean up the attribute structures for (j = 0; j < NUM_THREADS; j++) { hthread_attr_destroy( &attr[j] ); } printf ("-- Complete --\n"); // Return from main return 0; }
//int main( int argc, char *argv[] ) int run_tests() { if (NUM_THREADS > NUM_CPUS){ printf("CANNOT USE MORE THAN (%d) HETEROGENEOUS THREADS!!!!\r\n",NUM_CPUS); return (-1); } // Timer variables xps_timer_t timer; int time_create, time_start, time_stop; // Thread attribute structures Huint sta[NUM_THREADS]; void* retval[NUM_THREADS]; hthread_t tid[NUM_THREADS]; hthread_attr_t attr[NUM_THREADS]; targ_t thread_arg[NUM_THREADS]; // Setup Cache XCache_DisableDCache(); XCache_EnableICache(0xc0000801); // Create timer xps_timer_create(&timer, (int*)0x20400000); // Start timer xps_timer_start(&timer); // ************************************************************************************* extern unsigned char intermediate[]; extern unsigned int sort_handle_offset; unsigned int sort_handle = (sort_handle_offset) + (unsigned int)(&intermediate); // ************************************************************************************* float local_data[ARR_LENGTH]; int j = 0; printf("Code start address = 0x%08x\n", (unsigned int)&intermediate); for (j = 0; j < NUM_THREADS; j++) { // Initialize the attributes for the threads hthread_attr_init( &attr[j] ); hthread_attr_sethardware( &attr[j], (void*)base_array[j] ); } for (j = 0; j < ARR_LENGTH; j++) { local_data[j] = (ARR_LENGTH - j)*1.00; } #ifdef MY_DEBUG show_array(&local_data[0], ARR_LENGTH); #endif int num_ops = 0; for( num_ops = 0; num_ops < 2; num_ops = num_ops + 1) { printf("******* Round %d ********\n",num_ops); #ifdef USE_MB_THREAD printf("**** MB-based Threads ****\n"); #else printf("**** PPC-based Threads ****\n"); #endif for (j = 0; j < ARR_LENGTH; j++) { local_data[j] = ARR_LENGTH - j; } // Initialize thread arguments for ( j= 0; j < NUM_THREADS; j++) { thread_arg[j].data = &local_data[j*(ARR_LENGTH/NUM_THREADS)]; thread_arg[j].length = ARR_LENGTH/NUM_THREADS; } time_create = xps_timer_read_counter(&timer); // Create threads for (j = 0; j < NUM_THREADS; j++) { // Create the sort thread #ifdef USE_MB_THREAD // Create MB Thread sta[j] = hthread_create( &tid[j], &attr[j], (void*)sort_handle, (void*)(&thread_arg[j]) ); //printf( "Started MB Thread (TID = %d) \n", tid[j]); #else // Create SW Thread sta[j] = hthread_create( &tid[j], NULL, bubblesort_thread, (void*)(&thread_arg[j]) ); //printf( "Started SW Thread (TID = %d) \n", tid[j]); #endif } // Allow created threads to begin running and start timer time_start = xps_timer_read_counter(&timer); // Join on all threads for (j = 0; j < NUM_THREADS; j++) { hthread_join( tid[j], &retval[j] ); } // Grab stop time time_stop = xps_timer_read_counter(&timer); // Print out status for (j = 0; j < NUM_THREADS; j++) { printf("TID[%d] = 0x%08x, status = 0x%08x, retval = 0x%08x\n",j,tid[j],sta[j],(unsigned int)retval[j]); } printf("*********************************\n"); printf("Create time = %u\n",time_create); printf("Start time = %u\n",time_start); printf("Stop time = %u\n",time_stop); printf("*********************************\n"); printf("Creation time (|Start - Create|) = %u\n",time_start - time_create); printf("Elapsed time (|Stop - Start|) = %u\n",time_stop - time_start); printf("Total time (|Create - Stop|) = %u\n",time_stop - time_create); } #ifdef MY_DEBUG show_array(&local_data[0], ARR_LENGTH); check_array(&local_data[0], ARR_LENGTH); // Note there will be errors as the data set is not merged #endif // Clean up the attribute structures for (j = 0; j < NUM_THREADS; j++) { hthread_attr_destroy( &attr[j] ); } printf ("-- Complete --\n"); // Return from main return 0; }
int run_tests() { if (NUM_THREADS > NUM_CPUS){ printf("CANNOT USE MORE THAN (%d) HETEROGENEOUS THREADS!!!!\r\n", NUM_CPUS); return (-1); } // Timer variables xps_timer_t timer; int time_create, time_start, time_stop; // Thread attribute structures Huint sta[NUM_THREADS]; void* retval[NUM_THREADS]; hthread_t tid[NUM_THREADS]; hthread_attr_t attr[NUM_THREADS]; targ_t thread_arg[NUM_THREADS]; // Setup Cache XCache_DisableDCache(); XCache_EnableICache(0xc0000801); // Create timer xps_timer_create(&timer, (int*)0x20400000); // Start timer xps_timer_start(&timer); // ************************************************************************************* extern unsigned char intermediate[]; extern unsigned int distance_handle_offset; unsigned int distance_handle = (distance_handle_offset) + (unsigned int)(&intermediate); printf("Code start address = 0x%08x\n", (unsigned int)&intermediate); // ************************************************************************************* int vals_x0[ARR_LENGTH]; int vals_x1[ARR_LENGTH]; int vals_y0[ARR_LENGTH]; int vals_y1[ARR_LENGTH]; int vals_ds[ARR_LENGTH]; int j = 0; for (j = 0; j < NUM_THREADS; j++) { // Initialize the attributes for the threads hthread_attr_init( &attr[j] ); hthread_attr_sethardware( &attr[j], (void*)base_array[j] ); } for (j = 0; j < ARR_LENGTH; j++) { vals_x0[j] = ARR_LENGTH - j; vals_y0[j] = ARR_LENGTH - j; vals_x1[j] = ARR_LENGTH - j + 1; vals_y1[j] = ARR_LENGTH - j; } #ifdef MY_DEBUG #endif int num_ops = 0; for( num_ops = 0; num_ops < 2; num_ops = num_ops + 1) { printf("******* Round %d ********\n",num_ops); #ifdef USE_MB_THREAD printf("**** MB-based Threads ****\n"); #else printf("**** PPC-based Threads ****\n"); #endif for (j = 0; j < ARR_LENGTH; j++) { vals_x0[j] = ARR_LENGTH - j; } // Initialize thread arguments int num_items = ARR_LENGTH/NUM_THREADS; int extra_items = ARR_LENGTH - (num_items*NUM_THREADS); for ( j= 0; j < NUM_THREADS; j++) { thread_arg[j].x0s = &vals_x0[j*(num_items)]; thread_arg[j].y0s = &vals_y0[j*(num_items)]; thread_arg[j].x1s = &vals_x1[j*(num_items)]; thread_arg[j].y1s = &vals_y1[j*(num_items)]; thread_arg[j].distances = &vals_ds[j*(num_items)]; thread_arg[j].length = num_items; } // Add in extra items for the last thread if needed thread_arg[j-1].length += extra_items; time_create = xps_timer_read_counter(&timer); // Create threads for (j = 0; j < NUM_THREADS; j++) { // Create the distance thread #ifdef USE_MB_THREAD // Create MB Thread sta[j] = hthread_create( &tid[j], &attr[j], (void*)distance_handle, (void*)(&thread_arg[j]) ); //printf( "Started MB Thread (TID = %d) \n", tid[j]); #else // Create SW Thread sta[j] = hthread_create( &tid[j], NULL, distance_thread, (void*)(&thread_arg[j]) ); //printf( "Started SW Thread (TID = %d) \n", tid[j]); #endif } // Allow created threads to begin running and start timer time_start = xps_timer_read_counter(&timer); // Join on all threads for (j = 0; j < NUM_THREADS; j++) { hthread_join( tid[j], &retval[j] ); } // Grab stop time time_stop = xps_timer_read_counter(&timer); // Print out status for (j = 0; j < NUM_THREADS; j++) { printf("TID[%d] = 0x%08x, status = 0x%08x, retval = 0x%08x\n",j,tid[j],sta[j],(unsigned int)retval[j]); } printf("*********************************\n"); printf("Create time = %u\n",time_create); printf("Start time = %u\n",time_start); printf("Stop time = %u\n",time_stop); printf("*********************************\n"); printf("Creation time (|Start - Create|) = %u\n",time_start - time_create); printf("Elapsed time (|Stop - Start|) = %u\n",time_stop - time_start); printf("Total time (|Create - Stop|) = %u\n",time_stop - time_create); } #ifdef MY_DEBUG for (j = 0; j < ARR_LENGTH; j++) { printf("D(%d) = %d\n",j,vals_ds[j]); } #endif // Clean up the attribute structures for (j = 0; j < NUM_THREADS; j++) { hthread_attr_destroy( &attr[j] ); } printf ("-- Complete --\n"); // Return from main return 0; }
int run_tests() { // Timer variables xps_timer_t timer; int time_create, time_start, time_unlock, time_stop; // Mutex hthread_mutex_t * mutex = (hthread_mutex_t*)malloc( sizeof(hthread_mutex_t) ); hthread_mutex_init( mutex, NULL ); float min; // Thread attribute structures Huint sta[NUM_THREADS]; void* retval[NUM_THREADS]; hthread_t tid[NUM_THREADS]; hthread_attr_t attr[NUM_THREADS]; targ_t thread_arg[NUM_THREADS]; // Setup Cache XCache_DisableDCache(); XCache_EnableICache(0xc0000801); // Create timer xps_timer_create(&timer, (int*)0x20400000); // Start timer xps_timer_start(&timer); // ************************************************************************************* extern unsigned char intermediate[]; extern unsigned int min_handle_offset; unsigned int min_handle = (min_handle_offset) + (unsigned int)(&intermediate); // ************************************************************************************* printf("Code start address = 0x%08x\n", (unsigned int)&intermediate); int i = 0; float main_array[ARRAY_LENGTH]; printf("Addr of array = 0x%08x\n",(unsigned int)&main_array[0]); for (i = 0; i < ARRAY_LENGTH; i++) { main_array[i] = (i+2)*3.14f; } int num_items = ARRAY_LENGTH/NUM_THREADS; int extra_items = ARRAY_LENGTH - (num_items*NUM_THREADS); float * start_addr = &main_array[0]; for (i = 0; i < NUM_THREADS; i++) { // Initialize the attributes for the hardware threads hthread_attr_init( &attr[i] ); hthread_attr_sethardware( &attr[i], (void*)base_array[i] ); // Initialize thread arguments thread_arg[i].num_items = num_items; thread_arg[i].data_ptr = start_addr; thread_arg[i].min_mutex = mutex; thread_arg[i].min = &min; start_addr+=num_items; } // Add in extra items for the last thread if needed thread_arg[i-1].num_items += extra_items; int num_ops = 0; for( num_ops = 0; num_ops < 2; num_ops = num_ops + 1) { printf("******* Round %d ********\n",num_ops); #ifdef USE_MB_THREAD printf("**** MB-based Threads ****\n"); #else printf("**** PPC-based Threads ****\n"); #endif min = 9999999; // Lock mutex before hand so that timing will not include thread creation time hthread_mutex_lock(mutex); // Start timing thread create time_create = xps_timer_read_counter(&timer); for (i = 0; i < NUM_THREADS; i++) { // Create the worker threads #ifdef USE_MB_THREAD // Create MB Thread sta[i] = hthread_create( &tid[i], &attr[i], (void*)(min_handle), (void*)(&thread_arg[i]) ); #else // Create SW Thread sta[i] = hthread_create( &tid[i], NULL, min_thread, (void*)(&thread_arg[i]) ); #endif } // Allow created threads to begin running and start timer time_start = xps_timer_read_counter(&timer); hthread_mutex_unlock(mutex); time_unlock = xps_timer_read_counter(&timer); // Wait for the threads to exit //printf( "Waiting for thread(s) to complete... \n" ); for (i = 0; i < NUM_THREADS; i++) { hthread_join( tid[i], &retval[i] ); } time_stop = xps_timer_read_counter(&timer); // Display results printf("Min = %f\n",min); for (i = 0; i < NUM_THREADS; i++) { printf("TID = 0x%08x, status = 0x%08x, retval = 0x%08x\n",tid[i],sta[i],(Huint)retval[i]); } printf("*********************************\n"); printf("Create time = %u\n",time_create); printf("Start time = %u\n",time_start); printf("Unlock time = %u\n",time_unlock); printf("Stop time = %u\n",time_stop); printf("*********************************\n"); printf("Creation time (|Start - Create|) = %u\n",time_start - time_create); printf("Unlock time (|Unlock - Start|) = %u\n",time_unlock - time_start); printf("Elapsed time (|Stop - Start|) = %u\n",time_stop - time_start); } hthread_mutex_destroy( mutex ); free( mutex ); // Clean up the attribute structures for (i = 0; i < NUM_THREADS; i++) { hthread_attr_destroy( &attr[i] ); } printf ("-- Complete --\n"); // Return from main return 0; }