/* * Copyright 1993-2010 NVIDIA Corporation. All rights reserved. * * Please refer to the NVIDIA end user license agreement (EULA) associated * with this source code for terms and conditions that govern your use of * this software. Any use, reproduction, disclosure, or distribution of * this software and related documentation outside the terms of the EULA * is strictly prohibited. * */ /* Template project which demonstrates the basics on how to setup a project * example application. * Host code. */ // includes, system #include #include #include #include #include using namespace std; // includes CUDA #include #include "saxpy.h" __global__ void saxpy_kernel(float *vector_SAXPY, float A, float *vector_X, float *vector_Y, int N) { // A VOUS DE CODER } //////////////////////////////////////////////////////////////////////////////// // declaration, forward void runTest( int argc, char** argv); //////////////////////////////////////////////////////////////////////////////// // Program main //////////////////////////////////////////////////////////////////////////////// int main( int argc, char** argv) { runTest( argc, argv); } __host__ static int iDivUp(int a, int b) { return ((a % b != 0) ? (a / b + 1): (a/b)); } //////////////////////////////////////////////////////////////////////////////// //! Run a simple test for CUDA //////////////////////////////////////////////////////////////////////////////// void runTest( int argc, char** argv) { cudaError_t error; unsigned long int N=256*1024; const unsigned int mem_size = N*sizeof(float); // allocate host memory float* h_vector_X = (float*) malloc(mem_size); float* h_vector_Y = (float*) malloc(mem_size); //Initilaisation des données d'entrée float A=1.0; for (int i=0;i découpage en threads // A VOUS DE CODER // lancement des threads executé sur la carte GPU // A VOUS DE CODER error = cudaEventRecord(start_mem, NULL); error = cudaEventSynchronize(start_mem); // copy result from device to host // A VOUS DE CODER // cleanup device memory // COMMENTAIRES A ENLEVER //cudaFree(d_vector_X); //cudaFree(d_vector_Y); //cudaFree(d_vector_SAXPY); error = cudaEventRecord(stop, NULL); // Wait for the stop event to complete error = cudaEventSynchronize(stop); msecTotal = 0.0f; error = cudaEventElapsedTime(&msecTotal, start, stop); float msecMem2 =0.0f; error = cudaEventElapsedTime(&msecMem2, start_mem, stop); msecMem+=msecMem2; printf("GPU execution time %f ms (memory management %2.2f \%)\n",msecTotal,(msecMem)/(msecTotal)*100); float sum_diff=0; for(int i=0;i