I am trying to make working a source codes from articls "Playing with OpenCL: Gaussian Blurring" and I found that the author did not include main file, so I try to make my own. I found that the variables which are assigned from arguments are not declared, but the main problem is that the function looks strange to me:
#include "args.h"
#include "gaussian.h"
#include "refu/Time/rfc_timer.h"
#include "stdio.h"
#include "stdlib.h"
#include <CL/cl.h>
bool readArguments(int argc, char *argv[],char** imgname,uint32_t* gaussianSize,float* gaussianSigma)
{
uint32_t i;
char gSizeYes,gSigmaYes;
gSizeYes = gSigmaYes = false;
*imgname=0;
/** read the arguments of the program **/
for(i=1;i<argc;i++)
{
if(strcmp(argv[i],"-h")==0)
{
printf("\n%s\n",helpStr);
returnfalse;
}
/** read the image name **/
elseif(strcmp(argv[i],"-i")==0)
{
*imgname = argv[i+1];
i++;
}
/** read the gaussian size **/
elseif(strcmp(argv[i],"-g")==0)
{
*gaussianSize = atoi(argv[i+1]);
i++;
//only accept odd sized gaussian
if((*gaussianSize)%2 == 0 && (*gaussianSize) > 1)
{
printf("Argument Error: The size of the squared gaussian kernel has to be an odd number greater than one.\n");
returnfalse;
}
gSizeYes = true;
}
/** read the gaussian sigma parameter **/
elseif(strcmp(argv[i],"-s")==0)
{
*gaussianSigma = atof(argv[i+1]);
i++;
gSigmaYes = true;
}
else
{
printf("Unrecognized program argument given. The correct program usage can be seen below:\n%s",helpStr);
returnfalse;
}
}
/** if arguments are not given take default value **/
if(*imgname == 0)
*imgname = DEFAULT_IMG_NAME;
if(gSizeYes == false)
*gaussianSize = DEFAULT_GAUSSIAN_SIZE;
if(gSigmaYes == false)
*gaussianSigma = DEFAULT_GAUSSIAN_SIGMA;
//success
returntrue;
}
As far as I understand this function, the variables are local. The function does return boolean but it does not have any reference. Do you understand how this function can work? It does not have references in the arguments:
int main(int argc, char* argv[])
{
double units;
uint32_t gaussianSize;
float gaussianSigma;
char* imgname;//the name of the image file, taken by the arguments
//init the Refu library
rfInit("errorLog","infoLog");
//read in the program's arguments
if(readArguments(argc,argv,&imgname,&gaussianSize,&gaussianSigma)==false)
return -1;
//start a timer to time the CPU performance
RF_Timer timer;
rfTimer_Init(&timer,RF_TIMER_MICROSECONDS);
#ifndef MEASURE_COMM_OVERHEAD
//perform CPU blurring
if(pna_blur_cpu(imgname,gaussianSize,gaussianSigma)==false)//time it
return -2;
//query the timer for the CPU
units = rfTimer_Query(&timer,RF_TIMER_MICROSECONDS);
printf("CPU Gaussian blurring took %f microseconds\n",units);
//reset the timer for the GPU
rfTimer_Query(&timer,RF_TIMER_MICROSECONDS);
#endif
//perform GPU blurring and then read the timer
if(pna_blur_gpu(imgname,gaussianSize,gaussianSigma)==false)
return -3;
units = rfTimer_Query(&timer,RF_TIMER_MICROSECONDS);//time it
printf("GPU Gaussian blurring took %f microseconds\n",units);
return 0;
}
Error on the line: rfInit("errorLog","infoLog");
1 2 3
main.cpp||In function 'int main(int, char**)':|
main.cpp|20|warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]|
main.cpp|20|warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]|
The function takes a pointer variable. The function thus needs a memory address. Not just any address, but one that contains a character and has characters in consecutive locations as well, until there is a character that has value null.
Pointer is a variable. Variable stores a value. The value in pointer is a number that is interpreted as a memory address.
ad1 ) no value
ad2 )
main.cpp|19|warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]|
W:\___NEW_PROJECTS\GaussianBlur\Gaussian_with_OpenCL\main.cpp|20|warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]|
convertion from limited variable to unlimited. Value should be "errorLog" and "infoLog" but I think it's pointer to constant. Not sure.
3) This works. No error. I thought that when it is pointer required for the function arguments so I should declare it there. But obviously, there is a pointer to char array, because arrays cannot be passed by value.
3 more errors
\main.cpp|24|undefined reference to `readArguments(int, char**, char**, unsigned int*, float*)'|
\main.cpp|31|undefined reference to `pna_blur_cpu(char*, unsigned int, float)'|\main.cpp|40|undefined reference to `pna_blur_gpu(char*, unsigned int, float)'|
what this mean? I would guess that the header file with function was not included, but this one was. #include "args.h"
contains the function readArguments
Q1. Yes, they have no value set. The value is undefined. You did try to pass such to function and got the "used uninitialized".
Q2. Same error as you had initially. You have const string literals and attempt to store their address in non-const pointers. A non-const pointer could be used to modify the memory that it points to, and an attempt to modify literal is undefined.
Q3. The array variables essentially refer to memory blocks that have been allocated in local scope. In other words, 'errorLog' can be used where a char pointer is expected. The initialization copies characters from a const string literal into the non-const array.
I have found some problems while I try to remake the function. While debugging in code::blocks strange things happen. I have added two new arguments -install and -load
arguments given:-install -image image1.BMP
what happens is that when I break/jump on the line 59:
if(strcmp(argv[i],"-install")==0)
the debugger skips the next lines:
1 2 3 4 5 6 7 8 9
{
#define INSTALL 1
}
else
{
int pom;
pom = strcmp(argv[i],"-install");
printf(" var pom = %s",pom);
}
even when I add break points into the branches, it does not enter.
This is very similar with the -image argument. I checked the Watch panel for actual values and argv[i] is set correctly to -install and then to -image. So I am confused why debugger skips the branches like the string were not found!