Exemple #1
0
int main(int argc, char** argv) {
  float area[2];
  float aTime = 0.0;
  float bTime = 0.0;
  
  int reps = argc > 1 ? atoi(argv[1]) :100;

  printf("ProgramCount [%d], size-of-float[%lu], size-of-float[%lu]\n",ispc::get_programCount(),sizeof(float), sizeof(float));
  
    for (int i =0; i<reps; i++) {
    reset_and_start_timer();
    area[0]= ptarray_signed_area_aos(polygon_aos,npoints);
    aTime += get_elapsed_mcycles();
  }

  for (int i =0; i<reps; i++) {
    reset_and_start_timer();
    area[1]= ispc::ptarray_signed_area_aos(polygon_aos,npoints);
    bTime += get_elapsed_mcycles();
  }

  printf("%-20s: [%.2f] M cycles %s, [%.2f] M cycles %s (%.2fx speedup).\n",
      "ST_AREA", aTime, "serial_aos", bTime, "ispc_aos",
      aTime/bTime);
  printf("%-20s: serial [%.2f], ispc [%.2f]\n", "results", area[0], area[1]);


  aTime = 0.0;
  bTime = 0.0;
  for (int i =0; i<reps; i++) {
    reset_and_start_timer();
    area[0]= ptarray_signed_area_soa(polygon_soa,npoints);
    aTime += get_elapsed_mcycles();
  }
  printf("sequential code is fine.\n");
 
  for (int i =0; i<reps; i++) {
    reset_and_start_timer();
    area[1]= ispc::ptarray_signed_area_soa(polygon_aos,npoints);
    bTime += get_elapsed_mcycles();
  }
  printf("%-20s: [%.2f] M cycles %s, [%.2f] M cycles %s (%.2fx speedup).\n",
      "ST_AREA", aTime, "serial_soa", bTime, "ispc_soa",
      aTime/bTime);
  printf("%-20s: serial [%.2f], ispc [%.2f]\n", "results", area[0], area[1]);

  return 0;
}
void mandelbrot_threads(float x0, float y0, float x1, float y1,
                       int width,int width_start, int width_end, int height, int maxIterations,
                       int output[])
{
    float dx = (x1 - x0) / width;
    float dy = (y1 - y0) / height;
    int flag=1;
    reset_and_start_timer();
    for (int j = 0; j < height; j++) {
        for (int i = width_start; i < width_end; ++i) {
            float x = x0 + i * dx;
            float y = y0 + j * dy;
            int index = (j * width + i);	    
            output[index] = mandel(x, y, maxIterations);
        }
    }
    double dt = get_elapsed_mcycles();
    printf("\n\t\t\t Thread took :\t[%.3f] millon cycles",dt);
}
int main(int argc, char ** argv) {
    if (argc < 4) {
        printf("Please input M, N and K\n");
        return 1;
    }
    int row = atoi(argv[1]);
    int col = atoi(argv[2]);
    int num_iterate = atoi(argv[3]);

    GameOfLife* game;
    if (row <= 0 || col <= 0) {
        game = new GameOfLife(6, 4);
        game->specificInit();
    }
    else {
        game = new GameOfLife(row, col);
        game->randomInit();
    }
    if (game->notTooLarge()) {
        game->print();
    }

    // start to record time consumption
    reset_and_start_timer();
    
    game->iterateAll(num_iterate);

   // stop timer and print out total cycles
    double one_round = get_elapsed_mcycles();
    if (game->notTooLarge()) {
        game->print();
    }
    printf("\n-------- Statistic Infomation --------\n\n");
    printf("time consumption:\t\t\t[%.3f] million cycles\n", one_round);

    delete(game);
    return 0;
}
Exemple #4
0
int main(int argc, char** argv) {
    if (argc != 2) {
        printf("usage: deferred_shading <input_file (e.g. data/pp1280x720.bin)>\n");
        return 1;
    }

    InputData *input = CreateInputDataFromFile(argv[1]);
    if (!input) {
        printf("Failed to load input file \"%s\"!\n", argv[1]);
        return 1;
    }

    Framebuffer framebuffer(input->header.framebufferWidth,
                            input->header.framebufferHeight);

    InitDynamicC(input);
#ifdef __cilk
    InitDynamicCilk(input);
#endif // __cilk

    int nframes = 5;
    double ispcCycles = 1e30;
    for (int i = 0; i < 5; ++i) {
        framebuffer.clear();
        reset_and_start_timer();
        for (int j = 0; j < nframes; ++j)
            ispc::RenderStatic(input->header, input->arrays,
                               VISUALIZE_LIGHT_COUNT,
                               framebuffer.r, framebuffer.g, framebuffer.b);
        double mcycles = get_elapsed_mcycles() / nframes;
        ispcCycles = std::min(ispcCycles, mcycles);
    }
    printf("[ispc static + tasks]:\t\t[%.3f] million cycles to render "
           "%d x %d image\n", ispcCycles,
           input->header.framebufferWidth, input->header.framebufferHeight);
    WriteFrame("deferred-ispc-static.ppm", input, framebuffer);

#ifdef __cilk
    double dynamicCilkCycles = 1e30;
    for (int i = 0; i < 5; ++i) {
        framebuffer.clear();
        reset_and_start_timer();
        for (int j = 0; j < nframes; ++j)
            DispatchDynamicCilk(input, &framebuffer);
        double mcycles = get_elapsed_mcycles() / nframes;
        dynamicCilkCycles = std::min(dynamicCilkCycles, mcycles);
    }
    printf("[ispc + Cilk dynamic]:\t\t[%.3f] million cycles to render image\n", 
           dynamicCilkCycles);
    WriteFrame("deferred-ispc-dynamic.ppm", input, framebuffer);
#endif // __cilk

    double serialCycles = 1e30;
    for (int i = 0; i < 5; ++i) {
        framebuffer.clear();
        reset_and_start_timer();
        for (int j = 0; j < nframes; ++j)
            DispatchDynamicC(input, &framebuffer);
        double mcycles = get_elapsed_mcycles() / nframes;
        serialCycles = std::min(serialCycles, mcycles);
    }
    printf("[C++ serial dynamic, 1 core]:\t[%.3f] million cycles to render image\n", 
           serialCycles);
    WriteFrame("deferred-serial-dynamic.ppm", input, framebuffer);

#ifdef __cilk
    printf("\t\t\t\t(%.2fx speedup from static ISPC, %.2fx from Cilk+ISPC)\n", 
           serialCycles/ispcCycles, serialCycles/dynamicCilkCycles);
#else
    printf("\t\t\t\t(%.2fx speedup from ISPC + tasks)\n", serialCycles/ispcCycles);
#endif // __cilk

    DeleteInputData(input);

    return 0;
}