MCPcopy Create free account
hub / github.com/NVIDIA/cuda-samples / runTest

Function runTest

cpp/0_Introduction/simpleTextureDrv/simpleTextureDrv.cpp:108–304  ·  view source on GitHub ↗

/////////////////////////////////////////////////////////////////////////// Run a simple test for CUDA ///////////////////////////////////////////////////////////////////////////

Source from the content-addressed store, hash-verified

106//! Run a simple test for CUDA
107////////////////////////////////////////////////////////////////////////////////
108void runTest(int argc, char **argv)
109{
110 bool bTestResults = true;
111
112 // initialize CUDA
113 CUfunction transform = NULL;
114
115 if (initCUDA(argc, argv, &transform) != CUDA_SUCCESS) {
116 exit(EXIT_FAILURE);
117 }
118
119 // load image from disk
120 float *h_data = NULL;
121 unsigned int width, height;
122 char *image_path = sdkFindFilePath(image_filename, argv[0]);
123
124 if (image_path == NULL) {
125 printf("Unable to find image file: '%s'\n", image_filename);
126 exit(EXIT_FAILURE);
127 }
128
129 sdkLoadPGM(image_path, &h_data, &width, &height);
130
131 size_t size = width * height * sizeof(float);
132 printf("Loaded '%s', %d x %d pixels\n", image_filename, width, height);
133
134 // load reference image from image (output)
135 float *h_data_ref = (float *)malloc(size);
136 char *ref_path = sdkFindFilePath(ref_filename, argv[0]);
137
138 if (ref_path == NULL) {
139 printf("Unable to find reference file %s\n", ref_filename);
140 exit(EXIT_FAILURE);
141 }
142
143 sdkLoadPGM(ref_path, &h_data_ref, &width, &height);
144
145 // allocate device memory for result
146 CUdeviceptr d_data = (CUdeviceptr)NULL;
147 checkCudaErrors(cuMemAlloc(&d_data, size));
148
149 // allocate array and copy image data
150 CUarray cu_array;
151 CUDA_ARRAY_DESCRIPTOR desc;
152 desc.Format = CU_AD_FORMAT_FLOAT;
153 desc.NumChannels = 1;
154 desc.Width = width;
155 desc.Height = height;
156 checkCudaErrors(cuArrayCreate(&cu_array, &desc));
157 CUDA_MEMCPY2D copyParam;
158 memset(&copyParam, 0, sizeof(copyParam));
159 copyParam.dstMemoryType = CU_MEMORYTYPE_ARRAY;
160 copyParam.dstArray = cu_array;
161 copyParam.srcMemoryType = CU_MEMORYTYPE_HOST;
162 copyParam.srcHost = h_data;
163 copyParam.srcPitch = width * sizeof(float);
164 copyParam.WidthInBytes = copyParam.srcPitch;
165 copyParam.Height = height;

Callers 1

mainFunction · 0.70

Calls 11

sdkFindFilePathFunction · 0.85
sdkLoadPGMFunction · 0.85
sdkCreateTimerFunction · 0.85
sdkStartTimerFunction · 0.85
sdkStopTimerFunction · 0.85
sdkGetTimerValueFunction · 0.85
sdkDeleteTimerFunction · 0.85
sdkSavePGMFunction · 0.85
checkCmdLineFlagFunction · 0.85
initCUDAFunction · 0.70
compareDataFunction · 0.50

Tested by

no test coverage detected