/////////////////////////////////////////////////////////////////////////// Run a simple test for CUDA ///////////////////////////////////////////////////////////////////////////
| 106 | //! Run a simple test for CUDA |
| 107 | //////////////////////////////////////////////////////////////////////////////// |
| 108 | void 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(©Param, 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; |
no test coverage detected