How could pass parameter in Cuda Visual profiler I would like to know How to pass N num argument i

Hi All

This is Sonia.I have sucessfully run a simple cuda program on cudaVisual profiler.But i will want to know how to run a General program and pass run time argument in it.

Following are the Code of My Program.I have already tried for it .but did not get success.

#include<stdio.h> 

#include<cuda.h>

__global__ void VecAdd(unsigned int *a,unsigned int *b,unsigned int *c,unsigned int  n)

{

				int i=blockIdx.x*blockDim.x+threadIdx.x;

				if(i<1000)

				c[i]=a[i]+b[i];

}

int main()

{

	   unsigned int *a_h,*b_h,*c_h,*a_d,*b_d,*c_d,i,n;

	printf("\nEnter the Width of Matrix");

	scanf("%ld",&n);

		size_t size=sizeof(unsigned int)*n;

		a_h=(unsigned int*)malloc(size);

	b_h=(unsigned int*)malloc(size);

	c_h=(unsigned int*)malloc(size);

		cudaMalloc((void**)&b_d,size);

	 cudaMalloc((void**)&c_d,size);

	 cudaMalloc((void**)&a_d,size);

	printf("\nEnter the Elements of First Matrix");

	for(i=0;i<n;i++)

	{

		scanf("%ld",&a_h[i]);

	}

	cudaMemcpy(a_d,a_h,size,cudaMemcpyHostToDevice);

	 printf("\nEnter the Elements of Second  Matrix");

		for(i=0;i<n;i++)

		{

				scanf("%ld",&b_h[i]);

	

		}

		cudaMemcpy(b_d,b_h,size,cudaMemcpyHostToDevice);

	

	int blocksize=(n/512==1?512:n);

	

		

		int nblock=n/blocksize+(n%blocksize==0?0:1);

		VecAdd<<<nblock,blocksize>>>(b_d,a_d,c_d,n);

		cudaMemcpy(c_h,c_d,size,cudaMemcpyDeviceToHost);

		for(i=0;i<n;i++)

		{

				printf("\n%ld",c_h[i]);

		}

		free(a_h);

	free(b_h);

	free(c_h);

	cudaFree(c_d);

		cudaFree(a_d);

		cudaFree(b_d);

		return 0;

}

Tell me is it possible?

Thanks in Advance

Under “Session” tab, in the “Session settings” dialog, there is “Arguments” input field: you should just put your command line arguments there.

Thanks cgorac

But I have alreday tried this thing.actual I want to know the proper way for passing argument of above program.

when I ran this program on Command prompt the output (see the outputsnapshot)and I tried to pass argument in profiler this way(see the Shapshot parameterorde).

Tell the Extact order of parameter passing

Thanks in Advance

Ah, sorry - I haven’t read your code, I just read your question, and replied immediately… You are mixing passing run-time arguments to the program (that was the question, and this is done through the command line, but this is not what your code is doing), and reading inputs from standard input (this is what your code is doing). You cannot pass these values for the profiler run this way. You have several options instead:

  1. Maybe you could check “Run in separate windows” check-box in the “Session settings” dialog in profiler, and then type in input values in this new window created when profiler started. But I never tried it this way, so I’m not sure is it going to work (and also, even if it works, you may hit the max. execution time limit, unless you’re typing very fast, or you don’t increase this limit in the same dialog).

  2. Instead, it is better to create a text file with all inputs, and then re-direct standard input of your program to this file (“foo” is your program, “input.txt” is file with input values):

./foo <input.txt

However, this will not work in the profiler, as standard input re-direction is something that is accomplished by shell, and profiler is not duplicating this functionality. So, either you’ll have to create a shell script (say foo.sh):

#! /bin/sh

./foo <input.txt

and then try to supply path to foo.sh under “Launch” field of “Session settings” dialog in the profile, or better you change your code so that the name of input file is command line argument, and then you just fopen() this file in your code (first you’d have to check that your main() got at least two arguments from command line), and fscanf() from this file, instead of doing scanf() from standard output. In this case, you would put your program name under “Launch” field, and your input data file name under “Arguments” field in the “Sessions settings” profiler dialog. (BTW, you could at the same time delete “Enter this/that” printouts - having these in the code is considered bad practice among Unix programmers anyway.)

Thanks cgorac