| 
						
						
							
								
							
						
						
					 | 
				
			
			 | 
			 | 
			
				@ -47,9 +47,8 @@
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 *       cuda_context that is associated with the handle, against which you
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 *       want to call SCCudaHlGetCudaModule().
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 *
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 * \todo Provide support for multiple cuda context storage and creating multiple
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 *       cuda modules against a cuda_context, although it is highly unlikely we
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 *       would need this feature.
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 * \todo Provide support for multiple cuda context storage, although it is
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 *       highly unlikely we would need this feature.
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 *
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 *       We also need to use a mutex for module_data.
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 */
 | 
			
		
		
	
	
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
				
			
			 | 
			 | 
			
				@ -187,6 +186,20 @@ void SCCudaHlCleanProfiles(void)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    return;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				}
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				/**
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 * \internal
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 * \brief Get a unique handle for a new module registration.  This new handle
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 *        returned uniquely represents a module.  All future calls to functions
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 *        requires suppling this handle.
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 *
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 * \param module_handle A unique module handle that needs to used to refer
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 *                      to data(like cuda_contexts, cuda_modules, device pointers).
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 */
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				static int SCCudaHlGetUniqueHandle(void)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				{
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    return module_handle++;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				}
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				/**
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 * \internal
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 * \brief Returns a SCCudaHlModuleData instance from the global data store
 | 
			
		
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
			
			 | 
			 | 
			
				@ -210,25 +223,61 @@ SCCudaHlModuleData *SCCudaHlGetModuleData(uint8_t handle)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    return data;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				}
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				/**
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 * \internal
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 * \brief Returns a SCCudaHlModuleCUmodule instance that matches the cumodule_handle
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 *        from a SCCudaHlModuleData.
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 *
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 * \param data             The module data this CUmodule belongs to, obtained by a call to
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 *                         SCCudaHlGetModuleData()
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 * \param cumodule_handle  The handle for the SCCudaHlModuleCUmodule that has to be returned.
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 *
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 * \retval The SCCudaHlModuleCUmodule instance that matches the handle.
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 */
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				static SCCudaHlModuleCUmodule *SCCudaHlGetModuleCUmodule(SCCudaHlModuleData *data, uint8_t cumodule_handle)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				{
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    SCCudaHlModuleCUmodule *cumodule = NULL;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    if (data == NULL) {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        SCLogError(SC_ERR_INVALID_ARGUMENT, "Argument data cannot be NULL");
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        return NULL;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    }
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    cumodule = data->cuda_modules;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    if (cumodule == NULL) {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        SCLogError(SC_ERR_CUDA_HANDLER_ERROR,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				                   "No cumodule registered by the cumodule_handle %"PRIu8, cumodule_handle);
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        return NULL;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    }
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    while (cumodule != NULL && cumodule->cuda_module_handle != cumodule_handle) {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        cumodule = cumodule->next;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    }
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    return cumodule;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				}
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				/**
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 * \brief Returns a cuda_module against the handle in the argument.
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 *
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 *        If a cuda_module is not present for a handle, it is created
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 *        and associated with this handle and the cuda_module is returned
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 *        in the argument.  If a cuda_module is already present for
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 *        a handle, it is returned.
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 *        in the argument.
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 *
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 * \param p_context Pointer to a cuda context instance that should be updated
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 *                  with a cuda context.
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 * \param p_module  Pointer to a cuda module instance that should be updated
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 *                  with a cuda module.
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 * \param handle    A unique handle which identifies a module.  Obtained from
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 *                  a call to SCCudaHlGetUniqueHandle().
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 *
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 * \retval  0 On success.
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 * \retval -1 On failure.
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 * \retval  A unique handle within the module that is associated with the
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 *          loaded CUmodule. Needed for future API calls.
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 * \retval  -1 on failure.
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 */
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				int SCCudaHlGetCudaModuleFromFile(CUmodule *p_module, const char *filename, int handle)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				{
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    SCCudaHlModuleData *data = NULL;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    SCCudaHlModuleCUmodule *new_module_cumodule = NULL;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    SCCudaHlModuleCUmodule *module_cumodules = NULL;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    if (p_module == NULL) {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        SCLogError(SC_ERR_INVALID_ARGUMENTS, "Error invalid arguments"
 | 
			
		
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
			
			 | 
			 | 
			
				@ -239,14 +288,14 @@ int SCCudaHlGetCudaModuleFromFile(CUmodule *p_module, const char *filename, int
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    /* check if the particular module that wants a CUDA module is already
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				     * registered or not.  If it is registered, check if a context has
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				     * been associated with the module.  If yes, then we can go ahead and
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				     * create a cuda module or return the reference to the cuda module if
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				     * we already have a cuda module associated with the module.  If no, "
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				     * log warning and get out of here */
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				     * create a cuda module and associate it with the module referenced by
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				     * the handle in the functions arguments. If no, log warning and get
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				     * out of here */
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    if ( ((data = SCCudaHlGetModuleData(handle)) == NULL) ||
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				         (data->cuda_context == 0)) {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        SCLogDebug("Module not registered or no cuda context associated with "
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				                   "this module.  You can't create a CUDA module without"
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				                   "associatin a context with a module first. To use this "
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				                   "associating a context with a module first. To use this "
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				                   "registration facility, first register a module using "
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				                   "context using SCCudaHlRegisterModule(), and then register "
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				                   "a cuda context with that module using "
 | 
			
		
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
			
			 | 
			 | 
			
				@ -255,41 +304,40 @@ int SCCudaHlGetCudaModuleFromFile(CUmodule *p_module, const char *filename, int
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        return -1;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    }
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    /* we already have a cuda module associated with this module.  Return the
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				     * cuda module */
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    if (data->cuda_module != 0) {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        p_module[0] = data->cuda_module;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        return 0;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    /* Register new CUmodule in the module */
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    new_module_cumodule = SCMalloc(sizeof(SCCudaHlModuleCUmodule));
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    if (new_module_cumodule == NULL) {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        SCLogError(SC_ERR_FATAL, "Fatal error encountered in SCCudaHlRegisterModule. Exiting...");
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        exit(EXIT_FAILURE);
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    }
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    memset(new_module_cumodule, 0, sizeof(SCCudaHlModuleCUmodule));
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    /* we don't have a cuda module associated with this module.  Create a
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				     * cuda module, update the module with this cuda module reference and
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				     * then return the module refernce back to the calling function using
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    /* Create a cuda module, update the module with this cuda module reference
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				     * and then return the module reference back to the calling function using
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				     * the argument */
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    if (SCCudaModuleLoad(p_module, filename) == -1)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        goto error;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    data->cuda_module = p_module[0];
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    return 0;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    new_module_cumodule->cuda_module = p_module[0];
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    new_module_cumodule->cuda_module_handle = SCCudaHlGetUniqueHandle();
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    /* insert it into the cuda_modules list for the module instance */
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    if (data->cuda_modules == NULL) {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        data->cuda_modules = new_module_cumodule;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        return new_module_cumodule->cuda_module_handle;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    }
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    module_cumodules = data->cuda_modules;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    while (module_cumodules->next != NULL)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        module_cumodules = module_cumodules->next;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    module_cumodules->next = new_module_cumodule;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    return new_module_cumodule->cuda_module_handle;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 error:
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    return -1;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				}
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				/**
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 * \internal
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 * \brief Get a unique handle for a new module registration.  This new handle
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 *        returned uniquely represents a module.  All future calls to functions
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 *        requires suppling this handle.
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 *
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 * \param module_handle A unique module handle that needs to used to refer
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 *                      to data(like cuda_contexts, cuda_modules, device pointers).
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 */
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				static int SCCudaHlGetUniqueHandle(void)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				{
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    return module_handle++;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				}
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				/**
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 * \brief Returns a cuda context against the handle in the argument.
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 *
 | 
			
		
		
	
	
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
				
			
			 | 
			 | 
			
				@ -368,20 +416,22 @@ int SCCudaHlGetCudaContext(CUcontext *p_context, char *cuda_profile, int handle)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 *
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 *        If a cuda_module is not present for a handle, it is created
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 *        and associated with this handle and the cuda_module is returned
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 *        in the argument.  If a cuda_module is already present for
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 *        a handle, it is returned.
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 *        in the argument.
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 *
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 * \param p_context Pointer to a cuda context instance that should be updated
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 *                  with a cuda context.
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 * \param p_module  Pointer to a cuda module instance that should be updated
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 *                  with a cuda module.
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 * \param handle    A unique handle which identifies a module.  Obtained from
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 *                  a call to SCCudaHlGetUniqueHandle().
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 *
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 * \retval  0 On success.
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 * \retval -1 On failure.
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 * \retval  A unique handle within the module that is associated with the
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 *          loaded CUmodule. Needed for future API calls.
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 * \retval  -1 on failure.
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 */
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				int SCCudaHlGetCudaModule(CUmodule *p_module, const char *ptx_image, int handle)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				{
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    SCCudaHlModuleData *data = NULL;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    SCCudaHlModuleCUmodule *new_module_cumodule = NULL;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    SCCudaHlModuleCUmodule *module_cumodules = NULL;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    if (p_module == NULL) {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        SCLogError(SC_ERR_INVALID_ARGUMENTS, "Error invalid arguments"
 | 
			
		
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
			
			 | 
			 | 
			
				@ -392,14 +442,14 @@ int SCCudaHlGetCudaModule(CUmodule *p_module, const char *ptx_image, int handle)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    /* check if the particular module that wants a CUDA module is already
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				     * registered or not.  If it is registered, check if a context has
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				     * been associated with the module.  If yes, then we can go ahead and
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				     * create a cuda module or return the reference to the cuda module if
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				     * we already have a cuda module associated with the module.  If no, "
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				     * log warning and get out of here */
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				     * create a cuda module and associate it with the module referenced by
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				     * the handle in the functions arguments. If no, log warning and get
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				     * out of here */
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    if ( ((data = SCCudaHlGetModuleData(handle)) == NULL) ||
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				         (data->cuda_context == 0)) {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        SCLogDebug("Module not registered or no cuda context associated with "
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				                   "this module.  You can't create a CUDA module without"
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				                   "associatin a context with a module first. To use this "
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				                   "associating a context with a module first. To use this "
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				                   "registration facility, first register a module using "
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				                   "context using SCCudaHlRegisterModule(), and then register "
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				                   "a cuda context with that module using "
 | 
			
		
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
			
			 | 
			 | 
			
				@ -408,22 +458,35 @@ int SCCudaHlGetCudaModule(CUmodule *p_module, const char *ptx_image, int handle)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        return -1;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    }
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    /* we already have a cuda module associated with this module.  Return the
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				     * cuda module */
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    if (data->cuda_module != 0) {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        p_module[0] = data->cuda_module;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        return 0;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    /* Register new CUmodule in the module */
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    new_module_cumodule = SCMalloc(sizeof(SCCudaHlModuleCUmodule));
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    if (new_module_cumodule == NULL) {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        SCLogError(SC_ERR_FATAL, "Fatal error encountered in SCCudaHlRegisterModule. Exiting...");
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        exit(EXIT_FAILURE);
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    }
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    memset(new_module_cumodule, 0, sizeof(SCCudaHlModuleCUmodule));
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    /* we don't have a cuda module associated with this module.  Create a
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				     * cuda module, update the module with this cuda module reference and
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				     * then return the module refernce back to the calling function using
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    /* Create a cuda module, update the module with this cuda module reference
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				     * and then return the module reference back to the calling function using
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				     * the argument */
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    if (SCCudaModuleLoadData(p_module, (void *)ptx_image) == -1)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        goto error;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    data->cuda_module = p_module[0];
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    return 0;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    new_module_cumodule->cuda_module = p_module[0];
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    new_module_cumodule->cuda_module_handle = SCCudaHlGetUniqueHandle();
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    /* insert it into the cuda_modules list for the module instance */
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    if (data->cuda_modules == NULL) {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        data->cuda_modules = new_module_cumodule;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        return new_module_cumodule->cuda_module_handle;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    }
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    module_cumodules = data->cuda_modules;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    while (module_cumodules->next != NULL)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        module_cumodules = module_cumodules->next;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    module_cumodules->next = new_module_cumodule;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    return new_module_cumodule->cuda_module_handle;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 error:
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    return -1;
 | 
			
		
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
			
			 | 
			 | 
			
				@ -441,10 +504,10 @@ int SCCudaHlGetCudaModule(CUmodule *p_module, const char *ptx_image, int handle)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 * \retval module_device_ptr Pointer to the device pointer instance on finding
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 *                           it; NULL otherwise.
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 */
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				SCCudaHlModuleDevicePointer *SCCudaHlCudaDevicePtrAvailable(SCCudaHlModuleData *data,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				SCCudaHlModuleDevicePointer *SCCudaHlCudaDevicePtrAvailable(SCCudaHlModuleCUmodule *cumodule,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				                                                            const char *name)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				{
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    SCCudaHlModuleDevicePointer *module_device_ptr = data->device_ptrs;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    SCCudaHlModuleDevicePointer *module_device_ptr = cumodule->device_ptrs;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    while (module_device_ptr != NULL &&
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				           strcmp(module_device_ptr->name, name) != 0) {
 | 
			
		
		
	
	
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
				
			
			 | 
			 | 
			
				@ -473,14 +536,19 @@ SCCudaHlModuleDevicePointer *SCCudaHlCudaDevicePtrAvailable(SCCudaHlModuleData *
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 *                   hold atleast size bytes in memory.
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 * \param handle     A unique handle which identifies a module.  Obtained from
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 *                   a call to SCCudaHlGetUniqueHandle().
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 * \param cumodule_handle   A handle that identifies the CUmodule within the above module.
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 *                   Obtained from a call to SCCudaHlGetCudaModule() or
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 *                   SCCudaHlGetCudaModuleFromFile().
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 *
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 * \retval  0 On success.
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 * \retval -1 On failure.
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 */
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				int SCCudaHlGetCudaDevicePtr(CUdeviceptr *device_ptr, const char *name,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				                             size_t size, void *host_ptr, int handle)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				                             size_t size, void *host_ptr, int handle,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				                             int cumodule_handle)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				{
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    SCCudaHlModuleData *data = NULL;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    SCCudaHlModuleCUmodule *cumodule = NULL;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    SCCudaHlModuleDevicePointer *new_module_device_ptr = NULL;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    SCCudaHlModuleDevicePointer *module_device_ptr = NULL;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
			
			 | 
			 | 
			
				@ -500,7 +568,7 @@ int SCCudaHlGetCudaDevicePtr(CUdeviceptr *device_ptr, const char *name,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				         (data->cuda_context == 0)) {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        SCLogDebug("Module not registered or no cuda context associated with "
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				                   "this module.  You can't create a CUDA module without"
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				                   "associatin a context with a module first. To use this "
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				                   "associating a context with a module first. To use this "
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				                   "registration facility, first register a module using "
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				                   "context using SCCudaHlRegisterModule(), and then register "
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				                   "a cuda context with that module using "
 | 
			
		
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
			
			 | 
			 | 
			
				@ -509,9 +577,17 @@ int SCCudaHlGetCudaDevicePtr(CUdeviceptr *device_ptr, const char *name,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        goto error;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    }
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    if ( (cumodule = SCCudaHlGetModuleCUmodule(data, cumodule_handle)) == NULL ) {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        SCLogDebug("CUmodule not registered with the module. Before you can request"
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				                   "a device pointer for a module you need to load the CUmodule into"
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				                   "the engine module using SCCudaHlGetCudaModule() or"
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				                   "SCCudaHlGetCudaModuleFromFile().");
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        goto error;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    }
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    /* if we already have a device pointer registered by this name return the
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				     * cuda device pointer instance */
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    if ( (module_device_ptr = SCCudaHlCudaDevicePtrAvailable(data, name)) != NULL) {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    if ( (module_device_ptr = SCCudaHlCudaDevicePtrAvailable(cumodule, name)) != NULL) {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        device_ptr[0] = module_device_ptr->d_ptr;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        return 0;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    }
 | 
			
		
		
	
	
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
				
			
			 | 
			 | 
			
				@ -542,12 +618,12 @@ int SCCudaHlGetCudaDevicePtr(CUdeviceptr *device_ptr, const char *name,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    device_ptr[0] = new_module_device_ptr->d_ptr;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    /* insert it into the device_ptr list for the module instance */
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    if (data->device_ptrs == NULL) {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        data->device_ptrs = new_module_device_ptr;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    if (cumodule->device_ptrs == NULL) {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        cumodule->device_ptrs = new_module_device_ptr;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        return 0;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    }
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    module_device_ptr = data->device_ptrs;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    module_device_ptr = cumodule->device_ptrs;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    while (module_device_ptr->next != NULL)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        module_device_ptr = module_device_ptr->next;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    module_device_ptr->next = new_module_device_ptr;
 | 
			
		
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
			
			 | 
			 | 
			
				@ -570,13 +646,16 @@ int SCCudaHlGetCudaDevicePtr(CUdeviceptr *device_ptr, const char *name,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 *                   module for its existance.
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 * \param handle     A unique handle which identifies a module.  Obtained from
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 *                   a call to SCCudaHlGetUniqueHandle().
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 *
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 * \param cumodule   A handle that identifies the CUmodule within the above module.
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 *                   Obtained from a call to SCCudaHlGetCudaModule() or
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 *                   SCCudaHlGetCudaModuleFromFile().
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 * \retval  0 On success.
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 * \retval -1 On failure.
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 */
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				int SCCudaHlFreeCudaDevicePtr(const char *name, int handle)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				int SCCudaHlFreeCudaDevicePtr(const char *name, int handle, int cumodule_handle)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				{
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    SCCudaHlModuleData *data = NULL;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    SCCudaHlModuleCUmodule *cumodule = NULL;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    SCCudaHlModuleDevicePointer *module_device_ptr = NULL;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    SCCudaHlModuleDevicePointer *temp_module_device_ptr = NULL;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
			
			 | 
			 | 
			
				@ -595,7 +674,7 @@ int SCCudaHlFreeCudaDevicePtr(const char *name, int handle)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				         (data->cuda_context == 0)) {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        SCLogDebug("Module not registered or no cuda context associated with "
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				                   "this module.  You can't create a CUDA module without"
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				                   "associatin a context with a module first. To use this "
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				                   "associating a context with a module first. To use this "
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				                   "registration facility, first register a module using "
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				                   "context using SCCudaHlRegisterModule(), and then register "
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				                   "a cuda context with that module using "
 | 
			
		
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
			
			 | 
			 | 
			
				@ -604,18 +683,25 @@ int SCCudaHlFreeCudaDevicePtr(const char *name, int handle)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        goto error;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    }
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    /* if we already have a device pointer registered by this name return the
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				     * cuda device pointer instance */
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    if ( (module_device_ptr = SCCudaHlCudaDevicePtrAvailable(data, name)) == NULL) {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    if ( (cumodule = SCCudaHlGetModuleCUmodule(data, cumodule_handle)) == NULL ) {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        SCLogDebug("CUmodule not registered with the module. Before you can request"
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				                   "a device pointer for a module you need to load the CUmodule into"
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				                   "the engine module using SCCudaHlGetCudaModule() or"
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				                   "SCCudaHlGetCudaModuleFromFile().");
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        goto error;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    }
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    /* if we do not have a device pointer registered by this name get out */
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    if ( (module_device_ptr = SCCudaHlCudaDevicePtrAvailable(cumodule, name)) == NULL) {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        goto error;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    }
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    SCCudaMemFree(module_device_ptr->d_ptr);
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    module_device_ptr->d_ptr = 0;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    if (module_device_ptr == data->device_ptrs) {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        data->device_ptrs = data->device_ptrs->next;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    if (module_device_ptr == cumodule->device_ptrs) {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        cumodule->device_ptrs = cumodule->device_ptrs->next;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    } else {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        temp_module_device_ptr = data->device_ptrs;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        temp_module_device_ptr = cumodule->device_ptrs;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        while (strcmp(temp_module_device_ptr->next->name, name) != 0) {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            temp_module_device_ptr = temp_module_device_ptr->next;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        }
 | 
			
		
		
	
	
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
				
			
			 | 
			 | 
			
				@ -781,6 +867,8 @@ int SCCudaHlDeRegisterModule(const char *name)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				{
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    SCCudaHlModuleData *data = NULL;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    SCCudaHlModuleData *prev_data = NULL;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    SCCudaHlModuleCUmodule *cumodule = NULL;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    SCCudaHlModuleCUmodule *temp_cumodule = NULL;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    SCCudaHlModuleDevicePointer *device_ptr = NULL;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    SCCudaHlModuleDevicePointer *temp_device_ptr = NULL;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    int module_handle = SCCudaHlGetModuleHandle(name);
 | 
			
		
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
			
			 | 
			 | 
			
				@ -795,23 +883,37 @@ int SCCudaHlDeRegisterModule(const char *name)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        return -1;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    }
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    /* the applicationg must take care to check that the following cuda context
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    /* the application must take care to check that the following cuda context
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				     * which is being freed is floating(not attached to any host thread) */
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    if (data->cuda_context != 0)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        SCCudaCtxPushCurrent(data->cuda_context);
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    /* looks like we do have a module registered by this name */
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    /* first clean the cuda device pointers */
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    device_ptr = data->device_ptrs;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    while (device_ptr != NULL) {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        temp_device_ptr = device_ptr;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        device_ptr = device_ptr->next;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        if (SCCudaMemFree(temp_device_ptr->d_ptr) == -1)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    /* looks like we do have a module registered by this name.
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				     * Go through all CUmodules registered in this module and
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				     * free cuda device pointers and unload the module.
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				     */
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    cumodule = data->cuda_modules;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    while (cumodule != NULL) {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        /* free all device pointers */
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        device_ptr = cumodule->device_ptrs;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        while (device_ptr != NULL) {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            temp_device_ptr = device_ptr;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            device_ptr = device_ptr->next;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            if (SCCudaMemFree(temp_device_ptr->d_ptr) == -1)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				                goto error;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            SCFree(temp_device_ptr->name);
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            SCFree(temp_device_ptr);
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        }
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        cumodule->device_ptrs = NULL;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        /* unload the cuda module */
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        temp_cumodule = cumodule;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        cumodule = cumodule->next;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        if (SCCudaModuleUnload(temp_cumodule->cuda_module) == -1)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            goto error;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        SCFree(temp_device_ptr->name);
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        SCFree(temp_device_ptr);
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        SCFree(temp_cumodule);
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    }
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    data->device_ptrs = NULL;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    data->cuda_modules = NULL;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    if (data->name != NULL)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        SCFree((void *)data->name);
 | 
			
		
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
			
			 | 
			 | 
			
				@ -819,12 +921,6 @@ int SCCudaHlDeRegisterModule(const char *name)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    /* clean the dispatcher function registered */
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    data->SCCudaHlDispFunc = NULL;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    /* unload the cuda module */
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    if (data->cuda_module != 0) {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        if (SCCudaModuleUnload(data->cuda_module) == -1)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            goto error;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    }
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    /* destroy the cuda context */
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    if (data->cuda_context != 0) {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        if (SCCudaCtxDestroy(data->cuda_context) == -1)
 | 
			
		
		
	
	
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
				
			
			 | 
			 | 
			
				
 
 |