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
8b3c0c8b
Valider
8b3c0c8b
rédigé
1 year ago
par
Nicolas MARIE
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
add __checkErrors function to reduce redondency
parent
dea77408
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Modifications
2
Masquer les modifications d'espaces
En ligne
Côte à côte
Affichage de
2 fichiers modifiés
Projet/CODE/apm/src/apm.c
+37
-64
37 ajouts, 64 suppressions
Projet/CODE/apm/src/apm.c
Projet/CODE/apm/src/apm_gpu.cu
+2
-3
2 ajouts, 3 suppressions
Projet/CODE/apm/src/apm_gpu.cu
avec
39 ajouts
et
67 suppressions
Projet/CODE/apm/src/apm.c
+
37
−
64
Voir le fichier @
8b3c0c8b
...
...
@@ -10,10 +10,27 @@
#include
<unistd.h>
#include
<sys/time.h>
#include
<sys/stat.h>
#include
<stdarg.h>
#define APM_DEBUG 0
// can't be inline as it is a variadic function
void
__checkErrors
(
const
int
isBad
,
const
char
*
fmt
,
...)
{
va_list
args
;
if
(
isBad
)
{
va_start
(
args
,
fmt
);
vfprintf
(
stderr
,
fmt
,
args
);
va_end
(
args
);
fputc
(
'\n'
,
stderr
);
exit
(
EXIT_FAILURE
);
}
}
char
*
read_input_file
(
char
*
filename
,
size_t
*
size
)
{
...
...
@@ -26,15 +43,11 @@ read_input_file(char *filename, size_t *size)
/* Open the text file */
fd
=
open
(
filename
,
O_RDONLY
);
if
(
fd
==
-
1
)
{
fprintf
(
stderr
,
"Unable to open the text file <%s>
\n
"
,
filename
);
return
NULL
;
}
__checkErrors
(
fd
==
-
1
,
"Unable to open the text file <%s>
\n
"
,
filename
);
/* Get the number of characters in the textfile */
fstat
(
fd
,
&
fs
);
int
stat
=
fstat
(
fd
,
&
fs
);
__checkErrors
(
stat
<
0
,
"Stat of file <%s> failed
\n
"
,
filename
);
fsize
=
fs
.
st_size
;
#if APM_DEBUG
...
...
@@ -43,13 +56,8 @@ read_input_file(char *filename, size_t *size)
/* Allocate data to copy the target text */
buf
=
malloc
(
fsize
*
sizeof
(
char
));
if
(
buf
==
NULL
)
{
fprintf
(
stderr
,
"Unable to allocate %ld byte(s) for main array
\n
"
,
fsize
);
return
NULL
;
}
__checkErrors
(
buf
==
NULL
,
"Unable to allocate %ld byte(s) for main array
\n
"
,
fsize
);
do
{
...
...
@@ -58,14 +66,8 @@ read_input_file(char *filename, size_t *size)
}
while
(
read_bytes
!=
0
);
if
(
total_bytes
!=
fsize
)
{
fprintf
(
stderr
,
"Unable to copy %ld byte(s) from text file "
"(%ld byte(s) copied)
\n
"
,
fsize
,
total_bytes
);
return
NULL
;
}
__checkErrors
(
total_bytes
!=
fsize
,
"Unable to copy %ld byte(s) "
"from text file (%ld byte(s) copied)
\n
"
,
fsize
,
total_bytes
);
#if APM_DEBUG
printf
(
"Number of read bytes: %ld
\n
"
,
total_bytes
);
...
...
@@ -134,33 +136,18 @@ main(int argc, char **argv)
filename
=
argv
[
2
];
/* Grab the filename containing the target text */
nb_patterns
=
argc
-
3
;
/* Get the number of patterns to search for */
pattern
=
malloc
(
nb_patterns
*
sizeof
(
char
*
));
if
(
pattern
==
NULL
)
/*Fill the pattern*/
{
fprintf
(
stderr
,
"Unable to allocate array of pattern of size %ld
\n
"
,
nb_patterns
);
return
1
;
}
__checkErrors
(
pattern
==
NULL
,
"Unable to allocate array "
"of pattern of size %ld
\n
"
,
nb_patterns
);
for
(
i
=
0
;
i
<
nb_patterns
;
i
++
)
/* Grab the patterns */
{
int
l
;
l
=
strlen
(
argv
[
i
+
3
]);
if
(
l
<=
0
)
{
fprintf
(
stderr
,
"Error while parsing argument %ld
\n
"
,
i
+
3
);
return
1
;
}
__checkErrors
(
l
<=
0
,
"Error while parsing argument %ld
\n
"
,
i
+
3
);
pattern
[
i
]
=
(
char
*
)
malloc
((
l
+
1
)
*
sizeof
(
char
));
if
(
pattern
[
i
]
==
NULL
)
{
fprintf
(
stderr
,
"Unable to allocate string of size %d
\n
"
,
l
);
return
1
;
}
__checkErrors
(
pattern
[
i
]
==
NULL
,
"Unable to allocate string "
"of size %d
\n
"
,
l
);
strncpy
(
pattern
[
i
],
argv
[
i
+
3
],
(
l
+
1
));
}
...
...
@@ -168,22 +155,13 @@ main(int argc, char **argv)
printf
(
"Approximate Pattern Mathing: "
"looking for %ld pattern(s) in file %s w/ distance of %d
\n
"
,
nb_patterns
,
filename
,
approx_factor
);
buf
=
read_input_file
(
filename
,
&
n_bytes
);
if
(
buf
==
NULL
)
{
fprintf
(
stderr
,
"Error: NULL pointer from reading input file."
);
return
1
;
}
buf
=
read_input_file
(
filename
,
&
n_bytes
);
__checkErrors
(
buf
==
NULL
,
"Error: NULL pointer from reading input file."
);
n_matches
=
malloc
(
nb_patterns
*
sizeof
(
size_t
));
/*Alloc the matches*/
if
(
n_matches
==
NULL
)
{
fprintf
(
stderr
,
"Error: unable to allocate memory for %ldB
\n
"
,
nb_patterns
*
sizeof
(
int
));
return
1
;
}
__checkErrors
(
n_matches
==
NULL
,
"Error: unable to "
"allocate memory for %ldB
\n
"
,
nb_patterns
*
sizeof
(
int
));
/*****
* BEGIN MAIN LOOP
...
...
@@ -197,14 +175,9 @@ main(int argc, char **argv)
unsigned
int
*
column
;
n_matches
[
i
]
=
0
;
column
=
malloc
((
size_pattern
+
1
)
*
sizeof
(
unsigned
int
));
if
(
column
==
NULL
)
{
fprintf
(
stderr
,
"Error: unable to allocate memory for column (%ldB)
\n
"
,
(
size_pattern
+
1
)
*
sizeof
(
unsigned
int
));
return
1
;
}
__checkErrors
(
column
==
NULL
,
"Error: unable to "
"allocate memory for column (%ldB)
\n
"
,
(
size_pattern
+
1
)
*
sizeof
(
unsigned
int
));
for
(
j
=
0
;
j
<
n_bytes
-
size_pattern
;
j
++
)
{
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
Projet/CODE/apm/src/apm_gpu.cu
+
2
−
3
Voir le fichier @
8b3c0c8b
...
...
@@ -20,8 +20,7 @@
//If you get out of memory errors, you should reduce this value
inline
void
inline
void
__cudaCheckErrors
(
char
const
*
msg
)
{
cudaError_t
cu_err
;
...
...
@@ -285,7 +284,7 @@ main(int argc, char **argv)
__cudaCheckErrors
(
"Unable to copy buffer onto device"
);
NB
=
(
n_bytes
/
NTBB
)
+
(((
n_bytes
%
NTBB
)
>
0
)
?
1
:
0
);
cudaMemset
(
result_dev
,
0
,
sizeof
(
int
));
__cudaCheckErrors
(
"Unable to init result to 0 on device"
);
...
...
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