So I have this code that was handed to me by the professor and I can't seem to figure out the linking and compiling.
He gave a bunch of cips.c (C Image Processing System) files. I made them compliant with nvcc so that they would compile if I used nvcc -o outname cips1.c cips2.c cips3.c main.c
But when I try to make main.c main.cu I get a bunch of errors relating to undeclared things.
My professor tried to steer me towards googling linking C and CUDA C using nvcc but I don't understand the discussions going on online completely. This I know as a result of trying to implement my understandings and failing.
Anyways the direction my professor pointed me in specific was compiling the cips.c files to .o files then linking them later. But something about having to declare all the functions that main.cu calls.
This is the direction I would like to take since it is what lies in my mind the clearest.
I have it running compiled with nvcc as a .c file. I would just like to get it to compile renamed to a .cu file and test the same main without kernels just to see if it works. Then I can continue to progress with the rest of the assignment.
I feel like I have healthy kernels ready to launch and a good idea of how to get the data in and back out of the GPU. I just can't get the functions in the cips.c files to talk to the .cu.
So below I'm posting the beginnings of a few of my files to give an idea.
Code
/***********************************************
*
* file c:\cips\round.c
*
* Functions: This file contains
* main
*
* Purpose:
* This program takes an image file and
* rounds if off by copying a part of it
* to another file.
*
* External Calls:
* imageio.c - does_not_exit
* get_image_size
* allocate_image_array
* read_image_array
* is_a_bmp
* read_bmp_file_header
* read_bm_header
* create_allocate_bmp_file
* write_image_array
* free_image_array
*
*
* Modifications:
* 31 March 1991 - created
* 8 May 1993 - Made this program
* command line driven.
* 6 August 1998 - Made this work with
* entire image arrays at once.
* 18 September 1998 - modified to work with
* all I O routines in imageio.c.
*
***********************************************/
#include "cips.h"
main (argc, argv)
int argc;
char *argv[];
{
char response[80];
char name[80], name2[80];
int i = 0, ie = 0, il = 0, j = 0, in_length = 0, out_length =
0, in_width = 0, out_width = 0;
short **the_image, **out_image;
struct bmpfileheader bmp_file_header;
struct bitmapheader bmheader;
int sat;
/******************************************
*
* Ensure the command line is correct.
*
******************************************/
if (argc < 5 || (argc > 5 && argc < 7)) {
printf ("\nusage: roundoff in-image out-image"
" length width [il ie]"
"\n"
"\n If you do not specify il ie"
" they will be set to 1 1."
"\n ll le will always be" " il+length and ie+width" "\n");
exit (0);
}
strcpy (name, argv[1]);
strcpy (name2, argv[2]);
out_length = atoi (argv[3]);
out_width = atoi (argv[4]);
if (argc > 5) {
il = atoi (argv[5]);
ie = atoi (argv[6]);
}
if (does_not_exist (name)) {
printf ("\nERROR input file %s does not exist", name);
exit (0);
}
get_image_size (name, &in_length, &in_width);
the_image = (short **) allocate_image_array (in_length, in_width);
read_image_array (name, the_image);
/******************************************
*
* Create the output image and allocate
* the output image array.
*
******************************************/
if (is_a_bmp (name)) {
read_bmp_file_header (name, &bmp_file_header);
read_bm_header (name, &bmheader);
bmheader.height = out_length;
bmheader.width = out_width;
create_allocate_bmp_file (name2, &bmp_file_header, &bmheader);
}
out_image = (short **) allocate_image_array (out_length, out_width);
/******************************************
*
* Copy the input image array to the output
* image array per the input parameters.
*
******************************************/
for (i = 0; i < out_length; i++)
for (j = 0; j < out_width; j++){
/* 20% brighter */
sat = 1.2 * (float) the_image[i + il][j + ie];
if (sat > 255) sat = 255;
out_image[i][j] = sat;
}
write_image_array (name2, out_image);
free_image_array (out_image, out_length);
free_image_array (the_image, in_length);
} /* ends main */
Code
/*******************************************
*
* read_image_array(...
*
* This routine reads the image data from
* a bmp image.
*
********************************************/
#include "cips.h"
read_image_array (char *file_name, short **array)
/* char *file_name;
short **array; */
{
int ok = 0;
if (is_a_bmp (file_name)) {
read_bmp_image (file_name, array);
ok = 1;
}
if (ok == 0) {
printf ("\nERROR could not read file %s", file_name);
exit (1);
}
} /* ends read_image_array */
So if I were to rename main.c to .cu what would I have to do to link these guys?
e:\
This post was edited by ass666 on Mar 25 2016 12:04am