| 19 | #include "megbrain/common.h" |
| 20 | |
| 21 | NvOFCudaAPI::NvOFCudaAPI( |
| 22 | CUcontext cuContext, CUstream inputStream, CUstream outputStream) |
| 23 | : m_inputStream(inputStream), |
| 24 | m_outputStream(outputStream), |
| 25 | m_cuContext(cuContext) { |
| 26 | typedef NV_OF_STATUS(NVOFAPI * PFNNvOFAPICreateInstanceCuda)( |
| 27 | uint32_t apiVer, NV_OF_CUDA_API_FUNCTION_LIST * cudaOf); |
| 28 | #if defined(_WIN32) |
| 29 | PFNNvOFAPICreateInstanceCuda NvOFAPICreateInstanceCuda = |
| 30 | (PFNNvOFAPICreateInstanceCuda)GetProcAddress( |
| 31 | m_hModule, "NvOFAPICreateInstanceCuda"); |
| 32 | #else |
| 33 | PFNNvOFAPICreateInstanceCuda NvOFAPICreateInstanceCuda = |
| 34 | (PFNNvOFAPICreateInstanceCuda)dlsym(m_hModule, "NvOFAPICreateInstanceCuda"); |
| 35 | #endif |
| 36 | if (!NvOFAPICreateInstanceCuda) { |
| 37 | mgb_throw( |
| 38 | MegBrainError, |
| 39 | "NVOF: Cannot find NvOFAPICreateInstanceCuda() entry in NVOF " |
| 40 | "library err type: NV_OF_ERR_OF_NOT_AVAILABLE"); |
| 41 | } |
| 42 | |
| 43 | m_ofAPI.reset(new NV_OF_CUDA_API_FUNCTION_LIST()); |
| 44 | |
| 45 | NVOF_API_CALL(NvOFAPICreateInstanceCuda(NV_OF_API_VERSION, m_ofAPI.get())); |
| 46 | NVOF_API_CALL(m_ofAPI->nvCreateOpticalFlowCuda(m_cuContext, &m_hOF)); |
| 47 | NVOF_API_CALL(m_ofAPI->nvOFSetIOCudaStreams(m_hOF, m_inputStream, m_outputStream)); |
| 48 | } |
| 49 | |
| 50 | NvOFCudaAPI::~NvOFCudaAPI() { |
| 51 | if (m_ofAPI) { |