feat(sliceSM): add sliceSM

This commit is contained in:
2025-11-24 23:21:59 +01:00
parent cb6856ccde
commit bf9a0a2941
11 changed files with 79 additions and 61 deletions

View File

@@ -1,10 +1,8 @@
// Project tasks configuration. See https://zed.dev/docs/tasks for documentation.
//
// Example:
[ [
{ {
"label": "Run", "label": "Run CUDA - Student_Cuda",
"command": "cbicc cuda clean jall run", "command": "cbicc cuda clean jall run",
"cwd": "Student_Cuda",
"use_new_terminal": false, "use_new_terminal": false,
"allow_concurrent_runs": false, "allow_concurrent_runs": false,
"reveal": "always", "reveal": "always",

View File

@@ -2,6 +2,9 @@ CompileFlags:
Add: Add:
- "-I/home/mse15/CUDA/toStudent/code/WCudaStudent/Student_Cuda/INC_SYMLINK/EXT" - "-I/home/mse15/CUDA/toStudent/code/WCudaStudent/Student_Cuda/INC_SYMLINK/EXT"
- "-I/home/mse15/CUDA/toStudent/code/WCudaStudent/Student_Cuda/INC_SYMLINK/PROJECT" - "-I/home/mse15/CUDA/toStudent/code/WCudaStudent/Student_Cuda/INC_SYMLINK/PROJECT"
- "-std=c++17"
- "-x"
- "cuda"
--- ---
Diagnostics: Diagnostics:
Suppress: "*" Suppress: "*"

View File

@@ -17,16 +17,21 @@ static __device__ float f(float x);
|* Implementation *| |* Implementation *|
\*---------------------------------------------------------------------*/ \*---------------------------------------------------------------------*/
__global__ void sliceSM(int nbSlice , float* ptrPiHatGM) __global__
{ void sliceSM(int nbSlice , float* ptrPiHatGM) {
// TODO SliceSM // TODO SliceSM
// Reception tabSM // Reception tabSM
extern __shared__ float tabSM[];
// ReductionIntraThread // ReductionIntraThread
reductionIntraThread(tabSM, nbSlice);
__syncthreads();
// Reduction de tabSM (use tools ReductionAdd) // Reduction de tabSM (use tools ReductionAdd)
ReductionAdd::reduce(tabSM, ptrPiHatGM);
// __syncthreads(); necessaire? ou? pas a la fin en tout cas // __syncthreads(); necessaire? ou? pas a la fin en tout cas
} }
/*--------------------------------------*\ /*--------------------------------------*\
|* Private *| |* Private *|
@@ -35,19 +40,33 @@ __global__ void sliceSM(int nbSlice , float* ptrPiHatGM)
/** /**
* remplit la sm * remplit la sm
*/ */
void reductionIntraThread(float* tabSM , int nbSlice) static
{ __device__
void reductionIntraThread(float* tabSM , int nbSlice) {
// TODO SliceSM // TODO SliceSM
// Warning: Il faut employer TID et TID_LOCAL // Warning: Il faut employer TID et TID_LOCAL
} const int TID = Thread2D::tid();
const int localTID = Thread2D::tidLocal();
const int NB_THREAD = Thread2D::nbThread();
__device__ float f(float x) const float delta_x = 1.f / (float)nbSlice;
{
return 4.f / (1.f + x * x); int s = TID;
tabSM[localTID] = 0.f;
while (s < nbSlice) {
float xi = s * delta_x;
tabSM[localTID] += f(xi);
s += NB_THREAD;
} }
}
__device__
float f(float x) {
return 4.f / (1.f + x * x);
}
/*----------------------------------------------------------------------*\ /*----------------------------------------------------------------------*\
|* End *| |* End *|
\*---------------------------------------------------------------------*/ \*---------------------------------------------------------------------*/

View File

@@ -25,34 +25,31 @@ extern __global__ void sliceSM(int nbSlice,float* ptrPiHatGM);
\*-------------------------------------*/ \*-------------------------------------*/
SliceSM::SliceSM(const Grid& grid , int nbSlice , double* ptrPiHat , bool isVerbose) : SliceSM::SliceSM(const Grid& grid , int nbSlice , double* ptrPiHat , bool isVerbose) :
RunnableGPU(grid, "SliceSM_" + to_string(nbSlice), isVerbose), // classe parente RunnableGPU(grid, "SliceSM_" + to_string(nbSlice), isVerbose),
// ptrPiHat(ptrPiHat),
ptrPiHat(ptrPiHat), // nbSlice(nbSlice) {
nbSlice(nbSlice) // this->sizeSM = grid.threadByBlock() * sizeof(float); //TODO SliceSM
{
this->sizeSM = -1; //TODO SliceSM
// MM // MM
{ {
// TODO SliceSM (pas oublier de mettre a zero, avec mallocfloat0 par exemple) // TODO SliceSM (pas oublier de mettre a zero, avec mallocfloat0 par exemple)
GM::mallocFloat0(&ptrPiHatGM);
// Tip: Il y a une methode dedier pour malloquer un float cote device et l'initialiser a zero // Tip: Il y a une methode dedier pour malloquer un float cote device et l'initialiser a zero
// //
// GM::mallocfloat0(&ptrPiHatGM); // GM::mallocfloat0(&ptrPiHatGM);
} }
} }
SliceSM::~SliceSM(void) SliceSM::~SliceSM(void) {
{
//TODO SliceSM //TODO SliceSM
} GM::free(ptrPiHatGM);
}
/*--------------------------------------*\ /*--------------------------------------*\
|* Methode *| |* Methode *|
\*-------------------------------------*/ \*-------------------------------------*/
void SliceSM::run() void SliceSM::run() {
{
// Etape 1 : lancer le kernel // Etape 1 : lancer le kernel
// Etape 2 : recuperer le resultat coter host (par exemple avec memcpyDToH_float) // Etape 2 : recuperer le resultat coter host (par exemple avec memcpyDToH_float)
// Etape 3 : finaliser le calcul de PI // Etape 3 : finaliser le calcul de PI
@@ -60,7 +57,12 @@ void SliceSM::run()
// Solution : double result; // et ramener dans result, transferer et finaliser ensuite dans ptrPiHat // Solution : double result; // et ramener dans result, transferer et finaliser ensuite dans ptrPiHat
// TODO SliceSM // TODO SliceSM
} sliceSM<<<dg,db,this->sizeSM>>>(this->nbSlice, this->ptrPiHatGM);
float result;
GM::memcpyDToH_float(&result, this->ptrPiHatGM);
const double delta_x = 1.0 / (double) this->nbSlice;
*this->ptrPiHat = (double) result * delta_x;
}
///////////////////////// /////////////////////////
// Rappel: // Rappel:

View File

@@ -8,8 +8,7 @@
|* Declaration *| |* Declaration *|
\*---------------------------------------------------------------------*/ \*---------------------------------------------------------------------*/
class SliceSM: public RunnableGPU class SliceSM: public RunnableGPU {
{
/*--------------------------------------*\ /*--------------------------------------*\
|* Constructor *| |* Constructor *|
\*-------------------------------------*/ \*-------------------------------------*/
@@ -51,7 +50,7 @@ class SliceSM: public RunnableGPU
size_t sizeSM; // [octet] size_t sizeSM; // [octet]
float* ptrPiHatGM; float* ptrPiHatGM;
}; };
/*----------------------------------------------------------------------*\ /*----------------------------------------------------------------------*\
|* End *| |* End *|

View File

@@ -11,29 +11,26 @@
|* Impelmentation *| |* Impelmentation *|
\*---------------------------------------------------------------------*/ \*---------------------------------------------------------------------*/
namespace sliceSM namespace sliceSM {
{
class BestGrid class BestGrid {
{
public: public:
static Grid get() static Grid get() {
{ const int MP = Hardware::getMPCount();
const int MP = Hardware::getMPCount(); const int CORE_MP = Hardware::getCoreCountMP();
// TODO SliceGMHOST grid // TODO SliceGMHOST grid
dim3 dg(MP, 6, 1);
dim3 db(CORE_MP, 2, 1);
Grid grid(dg, db);
// to remove once coded return grid;
{
Couts::redln("aie aie aie, your best grid won t build itself");
assert(false);
}
} }
}; };
} }
/*----------------------------------------------------------------------*\ /*----------------------------------------------------------------------*\
|* End *| |* End *|

View File

@@ -29,7 +29,7 @@ int main(int argc , char** argv)
// public // public
{ {
cudaContext.deviceId = 1; // in [0,2] width Server Cuda3 cudaContext.deviceId = 1; // in [0,2] width Server Cuda3
cudaContext.launchMode = LaunchModeMOO::USE; // USE TEST BENCHMARK FORCEBRUT cudaContext.launchMode = LaunchModeMOO::TEST; // USE TEST BENCHMARK FORCEBRUT
cudaContext.deviceDriver = DeviceDriver::LOAD_ALL; // LOAD_CURRENT LOAD_ALL cudaContext.deviceDriver = DeviceDriver::LOAD_ALL; // LOAD_CURRENT LOAD_ALL
cudaContext.deviceInfo = DeviceInfo::ALL_SIMPLE; // NONE ALL ALL_SIMPLE CURRENT cudaContext.deviceInfo = DeviceInfo::ALL_SIMPLE; // NONE ALL ALL_SIMPLE CURRENT

View File

@@ -34,6 +34,7 @@ using std::endl;
static void sliceGMHOST(); static void sliceGMHOST();
static void sliceGM(); static void sliceGM();
static void sliceSM();
static void montecarloMono(); static void montecarloMono();
@@ -59,8 +60,8 @@ int mainBenchmark()
// Slice // Slice
{ {
// sliceGMHOST(); // sliceGMHOST();
sliceGM(); // sliceGM();
//sliceSM(); sliceSM();
//sliceMulti(); //sliceMulti();
} }

View File

@@ -75,8 +75,8 @@ int mainBrutforce()
// Slice // Slice
{ {
// sliceGMHOST(&matlab); // sliceGMHOST(&matlab);
sliceGM(&matlab); // sliceGM(&matlab);
// sliceSM(&matlab); sliceSM(&matlab);
} }
// Montecarlo // Montecarlo

View File

@@ -52,17 +52,16 @@ int mainTest()
/** /**
* activer ci-dessous la version souhaiter * activer ci-dessous la version souhaiter
*/ */
void slice() void slice() {
{
// VTSliceGMHOST test1; // VTSliceGMHOST test1;
VTSliceGM test2; // VTSliceGM test2;
// VTSliceSM test3; VTSliceSM test3;
// test1.run(); // test1.run();
test2.run(); // test2.run();
// test3.run(); test3.run();
} }
/** /**
* activer ci-dessous la version souhaiter * activer ci-dessous la version souhaiter

View File

@@ -67,12 +67,12 @@ int mainUse()
void slice(bool& isOk) void slice(bool& isOk)
{ {
// SliceGmHostUse sliceGmHostUse(IS_VERBOSE); // SliceGmHostUse sliceGmHostUse(IS_VERBOSE);
SliceGmUse sliceGmUse(IS_VERBOSE); // SliceGmUse sliceGmUse(IS_VERBOSE);
// SliceSmUse sliceSmUse(IS_VERBOSE); SliceSmUse sliceSmUse(IS_VERBOSE);
// isOk &= sliceGmHostUse.isOk(IS_VERBOSE); // isOk &= sliceGmHostUse.isOk(IS_VERBOSE);
isOk &= sliceGmUse.isOk(IS_VERBOSE); // isOk &= sliceGmUse.isOk(IS_VERBOSE);
// isOk &= sliceSmUse.isOk(IS_VERBOSE); isOk &= sliceSmUse.isOk(IS_VERBOSE);
} }
/** /**