Sort all includes in src/gromacs
[alexxy/gromacs.git] / src / gromacs / gmxlib / cuda_tools / cudautils.cu
index 606a811692826343b6f812eb14d3b3150c21db30..44a18eaec48ca2bf09ef6900aa3b95c44f7a9657 100644 (file)
@@ -1,58 +1,62 @@
-/* -*- mode: c; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; c-file-style: "stroustrup"; -*-
+/*
+ * This file is part of the GROMACS molecular simulation package.
  *
+ * Copyright (c) 2012,2014, by the GROMACS development team, led by
+ * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
+ * and including many others, as listed in the AUTHORS file in the
+ * top-level source directory and at http://www.gromacs.org.
  *
- *                This source code is part of
- *
- *                 G   R   O   M   A   C   S
- *
- *          GROningen MAchine for Chemical Simulations
- *
- * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
- * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
- * Copyright (c) 2001-2012, The GROMACS development team,
- * check out http://www.gromacs.org for more information.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
+ * GROMACS is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1
  * of the License, or (at your option) any later version.
  *
- * If you want to redistribute modifications, please consider that
- * scientific software is very special. Version control is crucial -
- * bugs must be traceable. We will be happy to consider code for
- * inclusion in the official distribution, but derived work must not
- * be called official GROMACS. Details are found in the README & COPYING
- * files - if they are missing, get the official version at www.gromacs.org.
+ * GROMACS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
  *
- * To help us fund GROMACS development, we humbly ask that you cite
- * the papers on the package - you can find them in the top README file.
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GROMACS; if not, see
+ * http://www.gnu.org/licenses, or write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
  *
- * For more info, check our website at http://www.gromacs.org
+ * If you want to redistribute modifications to GROMACS, please
+ * consider that scientific software is very special. Version
+ * control is crucial - bugs must be traceable. We will be happy to
+ * consider code for inclusion in the official distribution, but
+ * derived work must not be called official GROMACS. Details are found
+ * in the README & COPYING files - if they are missing, get the
+ * official version at http://www.gromacs.org.
  *
- * And Hey:
- * Gallium Rubidium Oxygen Manganese Argon Carbon Silicon
+ * To help us fund GROMACS development, we humbly ask that you cite
+ * the research papers on the package. Check out http://www.gromacs.org.
  */
 
-#include <stdlib.h>
+#include "gmxpre.h"
 
-#include "gmx_fatal.h"
-#include "smalloc.h"
-#include "typedefs.h"
 #include "cudautils.cuh"
 
+#include <stdlib.h>
+
+#include "gromacs/legacyheaders/typedefs.h"
+#include "gromacs/utility/smalloc.h"
+
 /*** Generic CUDA data operation wrappers ***/
 
 /*! Launches synchronous or asynchronous host to device memory copy.
  *
  *  The copy is launched in stream s or if not specified, in stream 0.
  */
-static int cu_copy_D2H_generic(void * h_dest, void * d_src, size_t bytes, 
+static int cu_copy_D2H_generic(void * h_dest, void * d_src, size_t bytes,
                                bool bAsync = false, cudaStream_t s = 0)
 {
     cudaError_t stat;
-    
+
     if (h_dest == NULL || d_src == NULL || bytes == 0)
+    {
         return -1;
+    }
 
     if (bAsync)
     {
@@ -83,9 +87,11 @@ int cu_copy_D2H_async(void * h_dest, void * d_src, size_t bytes, cudaStream_t s
 }
 
 int cu_copy_D2H_alloc(void ** h_dest, void * d_src, size_t bytes)
-{ 
+{
     if (h_dest == NULL || d_src == NULL || bytes == 0)
+    {
         return -1;
+    }
 
     smalloc(*h_dest, bytes);
 
@@ -96,13 +102,15 @@ int cu_copy_D2H_alloc(void ** h_dest, void * d_src, size_t bytes)
  *
  *  The copy is launched in stream s or if not specified, in stream 0.
  */
-static int cu_copy_H2D_generic(void * d_dest, void * h_src, size_t bytes, 
+static int cu_copy_H2D_generic(void * d_dest, void * h_src, size_t bytes,
                                bool bAsync = false, cudaStream_t s = 0)
 {
     cudaError_t stat;
 
     if (d_dest == NULL || h_src == NULL || bytes == 0)
+    {
         return -1;
+    }
 
     if (bAsync)
     {
@@ -119,7 +127,7 @@ static int cu_copy_H2D_generic(void * d_dest, void * h_src, size_t bytes,
 }
 
 int cu_copy_H2D(void * d_dest, void * h_src, size_t bytes)
-{   
+{
     return cu_copy_H2D_generic(d_dest, h_src, bytes, false);
 }
 
@@ -127,7 +135,7 @@ int cu_copy_H2D(void * d_dest, void * h_src, size_t bytes)
  *  The copy is launched in stream s or if not specified, in stream 0.
  */
 int cu_copy_H2D_async(void * d_dest, void * h_src, size_t bytes, cudaStream_t s = 0)
-{   
+{
     return cu_copy_H2D_generic(d_dest, h_src, bytes, true, s);
 }
 
@@ -136,7 +144,9 @@ int cu_copy_H2D_alloc(void ** d_dest, void * h_src, size_t bytes)
     cudaError_t stat;
 
     if (d_dest == NULL || h_src == NULL || bytes == 0)
+    {
         return -1;
+    }
 
     stat = cudaMalloc(d_dest, bytes);
     CU_RET_ERR(stat, "cudaMalloc failed in cu_copy_H2D_alloc");
@@ -146,7 +156,7 @@ int cu_copy_H2D_alloc(void ** d_dest, void * h_src, size_t bytes)
 
 float cu_event_elapsed(cudaEvent_t start, cudaEvent_t end)
 {
-    float t = 0.0;
+    float       t = 0.0;
     cudaError_t stat;
 
     stat = cudaEventElapsedTime(&t, start, end);
@@ -165,10 +175,10 @@ int cu_wait_event(cudaEvent_t e)
     return 0;
 }
 
-/*! 
+/*!
  *  If time != NULL it also calculates the time elapsed between start and end and
  *  return this is milliseconds.
- */ 
+ */
 int cu_wait_event_time(cudaEvent_t end, cudaEvent_t start, float *time)
 {
     cudaError_t s;
@@ -211,11 +221,11 @@ void cu_free_buffered(void *d_ptr, int *n, int *nalloc)
 }
 
 /*!
- *  Reallocation of the memory pointed by d_ptr and copying of the data from 
- *  the location pointed by h_src host-side pointer is done. Allocation is 
- *  buffered and therefore freeing is only needed if the previously allocated 
+ *  Reallocation of the memory pointed by d_ptr and copying of the data from
+ *  the location pointed by h_src host-side pointer is done. Allocation is
+ *  buffered and therefore freeing is only needed if the previously allocated
  *  space is not enough.
- *  The H2D copy is launched in stream s and can be done synchronously or 
+ *  The H2D copy is launched in stream s and can be done synchronously or
  *  asynchronously (the default is the latter).
  */
 void cu_realloc_buffered(void **d_dest, void *h_src,
@@ -232,7 +242,7 @@ void cu_realloc_buffered(void **d_dest, void *h_src,
         return;
     }
 
-    /* reallocate only if the data does not fit = allocation size is smaller 
+    /* reallocate only if the data does not fit = allocation size is smaller
        than the current requested size */
     if (req_size > *curr_alloc_size)
     {