static char *channels_close() { write_channels(); free_udef(udef); if (lastdeletedmask) nfree(lastdeletedmask); rem_builtins(H_chon, my_chon); rem_builtins(H_dcc, C_dcc_irc); rem_tcl_commands(channels_cmds); rem_tcl_strings(my_tcl_strings); rem_tcl_ints(my_tcl_ints); rem_tcl_coups(mychan_tcl_coups); del_hook(HOOK_USERFILE, (Function) channels_writeuserfile); del_hook(HOOK_BACKUP, (Function) backup_chanfile); del_hook(HOOK_REHASH, (Function) channels_rehash); del_hook(HOOK_PRE_REHASH, (Function) channels_prerehash); del_hook(HOOK_MINUTELY, (Function) check_expired_bans); del_hook(HOOK_MINUTELY, (Function) check_expired_exempts); del_hook(HOOK_MINUTELY, (Function) check_expired_invites); Tcl_UntraceVar(interp, "global-chanset", TCL_TRACE_READS | TCL_TRACE_WRITES | TCL_TRACE_UNSETS, traced_globchanset, NULL); rem_help_reference("channels.help"); rem_help_reference("chaninfo.help"); module_undepend(MODULE_NAME); return NULL; }
void pwm_servos_write_to_hardware(const servos_t* servos) { uint16_t pulse_us[MAX_SERVO_COUNT]; uint16_t freq_channel[MAX_SERVO_COUNT / 2]; // Set pulse length per servo for (uint8_t i = 0; i < MAX_SERVO_COUNT; ++i) { pulse_us[i] = servo_magnitude * servos->servo[i].value + servo_center_pulse_us; } // Set update frequency per channel with conservative method: // if two servos on the same channel ask for two different frequencies, // then the lowest frequecy is used for (int8_t i = 0; i < MAX_SERVO_COUNT / 2; ++i) { freq_channel[i] = min( servos->servo[2 * i].repeat_freq, servos->servo[2 * i + 1].repeat_freq ); } if ( use_servos_7_8 == true ) { write_channels( 0, pulse_us[0], pulse_us[1], freq_channel[0]); write_channels( 1, pulse_us[2], pulse_us[3], freq_channel[1]); write_channels( 2, pulse_us[4], pulse_us[5], freq_channel[2]); write_channels( 3, pulse_us[6], pulse_us[7], freq_channel[3]); } else { write_channels( 0, pulse_us[0], pulse_us[1], freq_channel[0]); write_channels( 1, pulse_us[2], pulse_us[3], freq_channel[1]); write_channels( 2, pulse_us[4], pulse_us[5], freq_channel[2]); } }
/* Should be removed when the new config system is in place. */ static int tcl_savechannels(ClientData cd, Tcl_Interp *irp, int argc, char *argv[]) { BADARGS(1, 1, ""); if (!chanfile[0]) { Tcl_AppendResult(irp, "no channel file"); return TCL_ERROR; } write_channels(); return TCL_OK; }
static void channels_writeuserfile(void) { char s[1024]; FILE *f; int ret = 0; simple_sprintf(s, "%s~new", userfile); f = fopen(s, "a"); if (f) { ret = write_bans(f, -1); ret += write_exempts(f, -1); ret += write_invites(f, -1); fclose(f); } if (ret < 3) putlog(LOG_MISC, "*", USERF_ERRWRITE); write_channels(); }
int main(int argc, char** argv) { if (argc != 2) { printf("Usage: %s <iterations>\n", argv[0]); return (EXIT_FAILURE); } int iterations = atoi(argv[1]); printf("main_cuda()\n"); printf("Iterations: %d\n", iterations); bool ok = true; /* Read input file into buffer. */ unsigned char (**image_buffer_h)[CHANNELS]; if (ok) ok = read_image((unsigned char ***) &image_buffer_h); /* Allocate memory for image data. */ float (**image_h)[CHANNELS]; if (ok) ok = alloc_float_array((float ***) &image_h, B + HEIGHT + B, B + WIDTH + B, CHANNELS); /* Convert input. */ unsigned int i, j, c; if (ok) { for (i = 0; i < HEIGHT; i++) for (j = 0; j < WIDTH; j++) for (c = 0; c < CHANNELS; c++) image_h[i + B][j + B][c] = (float) image_buffer_h[i][j][c]; } /* Device memory allocation. */ float (**prev_image_d)[CHANNELS]; float (**curr_image_d)[CHANNELS]; float *prev_image_p; float *curr_image_p; if (ok) ok = alloc_float_array_cuda((float ***) &prev_image_d, &prev_image_p, B + HEIGHT + B, B + WIDTH + B, CHANNELS); if (ok) ok = alloc_float_array_cuda((float ***) &curr_image_d, &curr_image_p, B + HEIGHT + B, B + WIDTH + B, CHANNELS); /* Initialize filter in device memory space. */ float (**filter_d)[1]; float *filter_p; if (ok) ok = init_filter(&filter_d, &filter_p, filter); /* Device parameters for nVidia 9600GT (G94), passed to main filter function. */ /* nVidia G94 supports 8 resident blocks per SMP, 768 resident threads per SMP. */ unsigned int block_size = 64; // maximum 512 threads per block for nVidia G94 printf("Block size: %u\n", block_size); /* nVidia G94 supports 2-dimensional grids with a maximum of 65535 for x,y dimension. */ unsigned int grid_dim = HEIGHT * WIDTH / block_size; double sqr = sqrt(grid_dim); grid_dim = sqr; grid_dim++; printf("Grid: %ux%u\n", grid_dim, grid_dim); /* Start timing. */ float memcopy, compute; timestamp t_start; t_start = getTimestamp(); /* Copy image data to device. */ if (ok) ok = (cudaSuccess == cudaMemcpy(curr_image_p, &(image_h[0][0][0]), (B + HEIGHT + B) * (B + WIDTH + B) * CHANNELS * sizeof (float), cudaMemcpyHostToDevice)); memcopy = getElapsedtime(t_start); /* Clear host image data. */ memset(&(image_h[0][0][0]), 0, (B + HEIGHT + B) * (B + WIDTH + B) * CHANNELS * sizeof (float)); /* Apply filter. */ t_start = getTimestamp(); unsigned int n; if (ok) { for (n = 0; iterations == 0 || n < iterations; n++) { /* Fill borders with edge image data. */ fill_borders(curr_image_d, HEIGHT, WIDTH); /* Apply filter. */ apply_filter_cuda(prev_image_d, curr_image_d, filter_d, block_size, grid_dim); /* Switch current / previous image buffers. */ float (**temp)[CHANNELS]; temp = prev_image_d; prev_image_d = curr_image_d; curr_image_d = temp; float *tmp; tmp = prev_image_p; prev_image_p = curr_image_p; curr_image_p = tmp; } } /* Stop time measurement, print time. */ cudaThreadSynchronize(); compute = getElapsedtime(t_start); t_start = getTimestamp(); /* Copy processed image data from device. */ if (ok) ok = (cudaSuccess == cudaMemcpy(&(image_h[0][0][0]), curr_image_p, (B + HEIGHT + B) * (B + WIDTH + B) * CHANNELS * sizeof (float), cudaMemcpyDeviceToHost)); memcopy += getElapsedtime(t_start); printf("Completed in %.3f sec\n", compute / 1000); printf("Memory copy in %.3f sec\n", memcopy / 1000); /* Convert output. */ if (ok) { for (i = 0; i < HEIGHT; i++) for (j = 0; j < WIDTH; j++) for (c = 0; c < CHANNELS; c++) image_buffer_h[i][j][c] = (unsigned char) image_h[i + B][j + B][c]; } /* Create output files, one for each channel. */ if (ok) ok = write_channels(image_buffer_h, HEIGHT, WIDTH); /* Free allocated memory. */ dealloc_uchar_array((unsigned char ***) &image_buffer_h); dealloc_float_array((float ***) &image_h); dealloc_float_array_cuda((float ***) &prev_image_d, &prev_image_p); dealloc_float_array_cuda((float ***) &curr_image_d, &curr_image_p); destroy_filter(&filter_d, &filter_p); return ok ? (EXIT_SUCCESS) : (EXIT_FAILURE); }
static void channels_rehash() { /* add channels from the chanfile but don't remove missing ones */ read_channels(1, 0); write_channels(); }
static void channels_prerehash() { write_channels(); }
int main(int argc, char** argv) { unsigned int i, j, c, n; bool ok = true; /* Read input file into buffer. */ unsigned char (**input_buffer)[CHANNELS]; if (ok) ok = read_image((unsigned char ***) &input_buffer); /* Allocate memory for image data. */ float (**input_image_data)[CHANNELS]; if (ok) ok = alloc_float_array((float ***) &input_image_data, B + HEIGHT + B, B + WIDTH + B, CHANNELS); float (**output_image_data)[CHANNELS]; if (ok) ok = alloc_float_array((float ***) &output_image_data, B + HEIGHT + B, B + WIDTH + B, CHANNELS); /* Convert input. */ if (ok) { for (c = 0; c < CHANNELS; c++) for (i = 0; i < HEIGHT; i++) for (j = 0; j < WIDTH; j++) output_image_data[i + B][j + B][c] = (float) input_buffer[i][j][c]; } /* Start timing. */ double t1, t2, real_time; struct tms tb1, tb2; double tickspersec = (double) sysconf(_SC_CLK_TCK); t1 = (double) times(&tb1); /* Apply filter. */ if (ok) { for (n = 0; n < ITERATIONS; n++) { /* Fill borders with outer image data. */ // south for (i = HEIGHT + B; i < HEIGHT + 2 * B; i++) for (j = B; j < B + WIDTH; j++) for (c = 0; c < CHANNELS; c++) output_image_data[i][j][c] = output_image_data[B + HEIGHT - 1][j][c]; // north for (i = 0; i < B; i++) // north for (j = B; j < B + WIDTH; j++) for (c = 0; c < CHANNELS; c++) output_image_data[i][j][c] = output_image_data[B][j][c]; // east for (i = B; i < B + HEIGHT; i++) for (j = WIDTH + B; j < WIDTH + 2 * B; j++) for (c = 0; c < CHANNELS; c++) output_image_data[i][j][c] = output_image_data[i][B + WIDTH - 1][c]; // west for (i = B; i < B + HEIGHT; i++) for (j = 0; j < B; j++) for (c = 0; c < CHANNELS; c++) output_image_data[i][j][c] = output_image_data[i][B][c]; // se for (i = HEIGHT + B; i < HEIGHT + 2 * B; i++) for (j = WIDTH + B; j < WIDTH + 2 * B; j++) for (c = 0; c < CHANNELS; c++) output_image_data[i][j][c] = output_image_data[B + HEIGHT - 1][B + WIDTH - 1][c]; // nw for (i = 0; i < B; i++) for (j = 0; j < B; j++) for (c = 0; c < CHANNELS; c++) output_image_data[i][j][c] = output_image_data[B][B][c]; // sw for (i = HEIGHT + B; i < HEIGHT + 2 * B; i++) for (j = 0; j < B; j++) for (c = 0; c < CHANNELS; c++) output_image_data[i][j][c] = output_image_data[B + HEIGHT - 1][B][c]; // ne for (i = 0; i < B; i++) for (j = WIDTH + B; j < WIDTH + 2 * B; j++) for (c = 0; c < CHANNELS; c++) output_image_data[i][j][c] = output_image_data[B][B + WIDTH - 1][c]; /* Use previous output as new input. */ float (**tmp)[CHANNELS]; tmp = input_image_data; input_image_data = output_image_data; output_image_data = tmp; /* Apply filter. */ apply_inner_filter(output_image_data, input_image_data, B + HEIGHT + B, B + WIDTH + B); apply_outer_filter(output_image_data, input_image_data, B + HEIGHT + B, B + WIDTH + B); } } /* Stop time measurement, print time. */ t2 = (double) times(&tb2); real_time = (double) (t2 - t1) / tickspersec; printf("Completed in %.3f sec\n", real_time); write_channels(output_image_data, B + HEIGHT + B, B + WIDTH + B); return (EXIT_SUCCESS); }
int main_serial_omp(int argc, char** argv) { if (argc != 3) { printf("Usage: %s <iterations> <convergence>\n", argv[0]); return (EXIT_FAILURE); } int iterations = atoi(argv[1]); int convergence = atoi(argv[2]); printf("main_serial_omp()\n"); printf("Iterations: %d, Convergence: %d\n", iterations, convergence); bool ok = true; /* Read input file into buffer. */ unsigned char (**image_buffer)[CHANNELS]; if (ok) ok = read_image((unsigned char ***) &image_buffer); /* Allocate memory for image data. */ float (**prev_image)[CHANNELS]; float (**curr_image)[CHANNELS]; if (ok) ok = alloc_float_array((float ***) &prev_image, B + HEIGHT + B, B + WIDTH + B, CHANNELS); if (ok) ok = alloc_float_array((float ***) &curr_image, B + HEIGHT + B, B + WIDTH + B, CHANNELS); /* Convert input. */ unsigned int i, j, c; if (ok) { for (i = 0; i < HEIGHT; i++) for (j = 0; j < WIDTH; j++) for (c = 0; c < CHANNELS; c++) curr_image[i + B][j + B][c] = (float) image_buffer[i][j][c]; } /* Start timing. */ double t1, t2, real_time; struct tms tb1, tb2; double tickspersec = (double) sysconf(_SC_CLK_TCK); t1 = (double) times(&tb1); unsigned int n; if (ok) { /* Apply filter. */ for (n = 0; (iterations == 0 || n < iterations) && (iterations != 0 || convergence != 0); n++) { /* Fill borders with outer image data. */ // south for (i = HEIGHT + B; i < HEIGHT + 2 * B; i++) for (j = B; j < B + WIDTH; j++) for (c = 0; c < CHANNELS; c++) curr_image[i][j][c] = curr_image[B + HEIGHT - 1][j][c]; // north for (i = 0; i < B; i++) // north for (j = B; j < B + WIDTH; j++) for (c = 0; c < CHANNELS; c++) curr_image[i][j][c] = curr_image[B][j][c]; // east for (i = B; i < B + HEIGHT; i++) for (j = WIDTH + B; j < WIDTH + 2 * B; j++) for (c = 0; c < CHANNELS; c++) curr_image[i][j][c] = curr_image[i][B + WIDTH - 1][c]; // west for (i = B; i < B + HEIGHT; i++) for (j = 0; j < B; j++) for (c = 0; c < CHANNELS; c++) curr_image[i][j][c] = curr_image[i][B][c]; // se for (i = HEIGHT + B; i < HEIGHT + 2 * B; i++) for (j = WIDTH + B; j < WIDTH + 2 * B; j++) for (c = 0; c < CHANNELS; c++) curr_image[i][j][c] = curr_image[B + HEIGHT - 1][B + WIDTH - 1][c]; // nw for (i = 0; i < B; i++) for (j = 0; j < B; j++) for (c = 0; c < CHANNELS; c++) curr_image[i][j][c] = curr_image[B][B][c]; // sw for (i = HEIGHT + B; i < HEIGHT + 2 * B; i++) for (j = 0; j < B; j++) for (c = 0; c < CHANNELS; c++) curr_image[i][j][c] = curr_image[B + HEIGHT - 1][B][c]; // ne for (i = 0; i < B; i++) for (j = WIDTH + B; j < WIDTH + 2 * B; j++) for (c = 0; c < CHANNELS; c++) curr_image[i][j][c] = curr_image[B][B + WIDTH - 1][c]; /* Apply inner filter, using omp parallel for. */ #pragma omp parallel { #pragma omp master if (n == 0) printf("Threads: %d\n", omp_get_num_threads()); apply_inner_filter_openmp(prev_image, curr_image, B + HEIGHT + B, B + WIDTH + B); } /* Apply outer filter. */ apply_outer_filter(prev_image, curr_image, B + HEIGHT + B, B + WIDTH + B); /* Switch current / previous image buffers. */ float (**temp)[CHANNELS]; temp = prev_image; prev_image = curr_image; curr_image = temp; /* Check for convergence. */ if (convergence > 0 && n % convergence == 0) { if (images_identical(curr_image, prev_image, B + HEIGHT + B, B + WIDTH + B)) { printf("Filter has converged after %d iterations.\n", n); break; } } } } /* Stop time measurement, print time. */ t2 = (double) times(&tb2); real_time = (double) (t2 - t1) / tickspersec; printf("Completed in %.3f sec\n", real_time); /* Convert output. */ if (ok) { for (i = 0; i < HEIGHT; i++) for (j = 0; j < WIDTH; j++) for (c = 0; c < CHANNELS; c++) image_buffer[i][j][c] = (unsigned char) curr_image[i + B][j + B][c]; } /* Create output files, one for each channel. */ write_channels(image_buffer, HEIGHT, WIDTH); /* Free allocated memory. */ dealloc_uchar_array((unsigned char ***) &image_buffer); dealloc_float_array((float ***) &curr_image); dealloc_float_array((float ***) &prev_image); return (EXIT_SUCCESS); }