Hi !
can we call a printf() on data allocated on device memory ?
Here is my code, please help me understand where the problem is. <img src=‘http://hqnveipbwb20/public/style_emoticons/<#EMO_DIR#>/crying.gif’ class=‘bbc_emoticon’ alt=‘:’(’ />
/* Includes */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
// bibliotheque CUDA
#include <cutil.h>
// header file
#include “full_scan_2.h”
// kernel code
#include “full_scan_2_kernel.cu”
void read_file(char *nom, struct data *db);
//chargement des donnees
int formated(int n, char c);
// petite fonction servant a aficher ‘n’ fois le caractere ‘c’
void runProg(int argc, char **argv);
// Device code
global void scan_ORF();
int main(int argc, char **argv)
{
if(argc<2)
{
fprintf(stderr, “usage : ./<nom_prog> *.tfa\n”);
return EXIT_FAILURE;
}
runProg(argc, argv);
CUT_EXIT(argc, argv);
}
void runProg(int argc, char **argv)
{
//demarrage carte GPGPU
CUT_DEVICE_INIT();
printf(“debut\n”);
int i/, j, k, l, m, n/; // variables de boucles etc
int nb_files = argc-1;
unsigned int timer = 0;
unsigned long mem_size_db = 1000 * nb_files;
unsigned int mem_size_fasta = 0;
for(i=0; i<nb_files; i++)
mem_size_fasta += strlen(argv[i+1]);
mem_size_fasta *= nb_files;
char **h_n_fasta; // tableau des noms de fichiers FASTA
h_n_fasta = (char **)calloc(nb_files, sizeof(char *));
assert(h_n_fasta != NULL);
for(i=0; i<nb_files; i++){
h_n_fasta[i] = (char *)calloc(strlen(argv[i+1]),sizeof(char));
assert(h_n_fasta[i] != NULL);
h_n_fasta[i] = strcpy(h_n_fasta[i],argv[i+1]);
}
struct data **h_db;
h_db = (struct data **) malloc(sizeof(struct data *) * nb_files);
for(i=0; i<nb_files; i++)
h_db[i] = (struct data *) malloc(sizeof(struct data) * TAILLE_D);
struct data d_db;
CUDA_SAFE_CALL(cudaMalloc((void **)&d_db, mem_size_dbsizeof(data)));
char d_n_fasta;
CUDA_SAFE_CALL(cudaMalloc((void **)&d_n_fasta, mem_size_fastasizeof(char)));
CUDA_SAFE_CALL(cudaMemcpy(d_n_fasta, h_n_fasta, mem_size_fasta, cudaMemcpyHostToDevice));
CUT_SAFE_CALL(cutCreateTimer(&timer));
CUT_SAFE_CALL(cutStartTimer(timer));
printf(“\nfichier : %d\n”, d_n_fasta[0]); // the problem might be HERE !
for(i=0; i<nb_files; i++)
read_file(h_n_fasta[i], h_db[i]);
// Check kernel execution error
CUT_CHECK_ERROR(“L’execution du kernel code a echouee\n”);
CUDA_SAFE_CALL(cudaMemcpy(d_db, h_db, mem_size_db, cudaMemcpyDeviceToHost));
CUT_SAFE_CALL(cutStopTimer(timer));
printf(“Processing time : %f (ms)\n”, cutGetTimerValue(timer));
CUT_SAFE_CALL(cutDeleteTimer(timer));
for(i=0; i<nb_files; i++)
free(h_n_fasta[i]);
free(h_n_fasta);
for(i=0; i<nb_files; i++)
free(h_db[i]);
free(h_db);
CUDA_SAFE_CALL(cudaFree(d_n_fasta));
CUDA_SAFE_CALL(cudaFree(d_db));
}
Greetings, External Image
bonhomme