Host code
| 114 | |
| 115 | // Host code |
| 116 | int main(int argc, char **argv) |
| 117 | { |
| 118 | printf("Vector Addition (Driver API)\n"); |
| 119 | int N = 50000; |
| 120 | size_t size = N * sizeof(float); |
| 121 | int attributeVal = 0; |
| 122 | |
| 123 | // Initialize |
| 124 | checkCudaErrors(cuInit(0)); |
| 125 | |
| 126 | cuDevice = findCudaDeviceDRV(argc, (const char **)argv); |
| 127 | |
| 128 | // Check that the selected device supports virtual address management |
| 129 | checkCudaErrors( |
| 130 | cuDeviceGetAttribute(&attributeVal, CU_DEVICE_ATTRIBUTE_VIRTUAL_ADDRESS_MANAGEMENT_SUPPORTED, cuDevice)); |
| 131 | printf("Device %d VIRTUAL ADDRESS MANAGEMENT SUPPORTED = %d.\n", cuDevice, attributeVal); |
| 132 | if (attributeVal == 0) { |
| 133 | printf("Device %d doesn't support VIRTUAL ADDRESS MANAGEMENT.\n", cuDevice); |
| 134 | exit(EXIT_WAIVED); |
| 135 | } |
| 136 | |
| 137 | // The vector addition happens on cuDevice, so the allocations need to be |
| 138 | // mapped there. |
| 139 | vector<CUdevice> mappingDevices; |
| 140 | mappingDevices.push_back(cuDevice); |
| 141 | |
| 142 | // Collect devices accessible by the mapping device (cuDevice) into the |
| 143 | // backingDevices vector. |
| 144 | vector<CUdevice> backingDevices = getBackingDevices(cuDevice); |
| 145 | CUctxCreateParams ctxCreateParams = {}; |
| 146 | |
| 147 | // Create context |
| 148 | checkCudaErrors(cuCtxCreate(&cuContext, &ctxCreateParams, 0, cuDevice)); |
| 149 | |
| 150 | // first search for the module path before we load the results |
| 151 | string module_path; |
| 152 | |
| 153 | std::ostringstream fatbin; |
| 154 | |
| 155 | if (!findFatbinPath(FATBIN_FILE, module_path, argv, fatbin)) { |
| 156 | exit(EXIT_FAILURE); |
| 157 | } |
| 158 | else { |
| 159 | printf("> initCUDA loading module: <%s>\n", module_path.c_str()); |
| 160 | } |
| 161 | |
| 162 | if (!fatbin.str().size()) { |
| 163 | printf("fatbin file empty. exiting..\n"); |
| 164 | exit(EXIT_FAILURE); |
| 165 | } |
| 166 | |
| 167 | // Create module from binary file (FATBIN) |
| 168 | checkCudaErrors(cuModuleLoadData(&cuModule, fatbin.str().c_str())); |
| 169 | |
| 170 | // Get function handle from module |
| 171 | checkCudaErrors(cuModuleGetFunction(&vecAdd_kernel, cuModule, "VecAdd_kernel")); |
| 172 | |
| 173 | // Allocate input vectors h_A and h_B in host memory |
nothing calls this directly
no test coverage detected