Skip to content
GitLab
Explorer
Connexion
Navigation principale
Rechercher ou aller à…
Projet
P
PGPU2023
Gestion
Activité
Membres
Labels
Programmation
Tickets
Tableaux des tickets
Jalons
Wiki
Wiki externe
Code
Requêtes de fusion
Dépôt
Branches
Validations
Étiquettes
Graphe du dépôt
Comparer les révisions
Extraits de code
Compilation
Pipelines
Jobs
Planifications de pipeline
Artéfacts
Déploiement
Releases
Registre de paquets
Registre de conteneur
Registre de modèles
Opération
Environnements
Modules Terraform
Surveillance
Incidents
Analyse
Données d'analyse des chaînes de valeur
Analyse des contributeurs
Données d'analyse CI/CD
Données d'analyse du dépôt
Expériences du modèle
Aide
Aide
Support
Documentation de GitLab
Comparer les forfaits GitLab
Forum de la communauté
Contribuer à GitLab
Donner votre avis
Raccourcis clavier
?
Extraits de code
Groupes
Projets
Afficher davantage de fils d'Ariane
Nicolas MARIE
PGPU2023
Validations
9e24fea4
Valider
9e24fea4
rédigé
1 year ago
par
Nicolas MARIE
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
fixe pi_cuda
parent
c038430e
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Modifications
1
Masquer les modifications d'espaces
En ligne
Côte à côte
Affichage de
1 fichier modifié
TDs/TD2/CODE/pi_cuda.cu
+10
-23
10 ajouts, 23 suppressions
TDs/TD2/CODE/pi_cuda.cu
avec
10 ajouts
et
23 suppressions
TDs/TD2/CODE/pi_cuda.cu
+
10
−
23
Voir le fichier @
9e24fea4
...
...
@@ -17,35 +17,23 @@
__global__
void
pi_kernel
(
double
*
d_pi
){
const
int
tid
=
blockIdx
.
x
*
blockDim
.
x
+
threadIdx
.
x
;
double
n_test
=
10E7
;
int
grid_size_x
=
512
;
int
block_size_x
=
256
;
int
tab_size
=
grid_size_x
*
block_size_x
;
int
trials_per_thread
=
(
int
)
n_test
/
tab_size
;
curandState
localState
;
curand_init
(
0
,
tid
,
0
,
&
localState
);
int
count
;
int
count
=
0
;
float
x
,
y
;
for
(
size_t
i
=
0
;
i
<
trials_per_thread
;
++
i
){
for
(
size_t
i
=
0
;
i
<
TRIALS_PER_THREAD
;
++
i
){
x
=
curand_uniform
(
&
localState
);
y
=
curand_uniform
(
&
localState
);
count
+=
x
*
x
+
y
*
y
<
1
;
}
d_pi
[
tid
]
=
4.
*
(
double
)
count
/
(
double
)
trials_per_thread
;
d_pi
[
tid
]
=
4.
*
(
double
)
count
/
(
double
)
TRIALS_PER_THREAD
;
}
int
main
(
int
argc
,
char
**
argv
)
{
double
n_test
=
10E7
;
int
grid_size_x
=
512
;
int
block_size_x
=
256
;
int
tab_size
=
grid_size_x
*
block_size_x
;
int
trials_per_thread
=
n_test
/
tab_size
;
uint64_t
i
;
double
pi
=
0.
;
double
pi
;
int
sz_in_bytes
=
sizeof
(
double
)
*
tab_size
;
int
sz_in_bytes
=
sizeof
(
double
)
*
TAB_SIZE
;
double
*
h_pi
;
double
*
d_pi
;
...
...
@@ -55,19 +43,18 @@ int main(int argc, char** argv) {
checkCudaErrors
(
cudaMalloc
((
void
**
)
&
d_pi
,
sz_in_bytes
));
checkCudaErrors
(
cudaMemset
(
d_pi
,
0
,
sz_in_bytes
));
dim3
dimBlock
(
block_size_x
,
1
,
1
);
dim3
dimGrid
(
grid_size_x
,
1
,
1
);
dim3
dimBlock
(
BLOCK_SIZE_X
,
1
,
1
);
dim3
dimGrid
(
GRID_SIZE_X
,
1
,
1
);
pi_kernel
<<<
dimGrid
,
dimBlock
>>>
(
d_pi
);
cudaDeviceSynchronize
();
getLastCudaError
(
"PI kernel failed"
);
checkCudaErrors
(
cudaMemcpy
(
h_pi
,
d_pi
,
sz_in_bytes
,
cudaMemcpyDeviceToHost
));
fprintf
(
stdout
,
"Pi ~= %lf
\n
"
,
h_pi
[
0
]);
for
(
i
=
0
;
i
<
tab_size
;
++
i
)
pi
=
0.
;
for
(
i
=
0
;
i
<
TAB_SIZE
;
++
i
)
pi
+=
h_pi
[
i
];
pi
/=
(
double
)
tab_size
;
pi
/=
(
double
)
TAB_SIZE
;
fprintf
(
stdout
,
"Pi ~= %lf
\n
"
,
pi
);
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
Aperçu
0%
Chargement en cours
Veuillez réessayer
ou
joindre un nouveau fichier
.
Annuler
You are about to add
0
people
to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Enregistrer le commentaire
Annuler
Veuillez vous
inscrire
ou vous
se connecter
pour commenter