]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Make some cudaError_t variables const
authorDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Thu, 16 Aug 2018 23:32:21 +0000 (01:32 +0200)
committerDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Thu, 16 Aug 2018 23:32:21 +0000 (01:32 +0200)
include/deal.II/lac/cuda_vector.h
source/lac/cuda_vector.cu

index 184c8c55b7c0ec3fad51690c8ae1641f8f118a65..c86b855858129065f09f4d22dbb1e7aef0bc3859 100644 (file)
@@ -311,7 +311,7 @@ namespace LinearAlgebra
       /**
        * Pointer to the array of elements of this vector.
        */
-      std::unique_ptr<Number, void (*)(Number *)> val;
+      std::unique_ptr<Number[], void (*)(Number *)> val;
 
       /**
        * Number of elements in the vector.
index e40b47c8029252dd51c475561dcd9ec4ce060259..12fe034189f7102431242f700dd61a81c95dbad3 100644 (file)
@@ -41,7 +41,7 @@ namespace LinearAlgebra
       void
       delete_device_vector(Number *device_ptr) noexcept
       {
-        cudaError_t error_code = cudaFree(device_ptr);
+        const cudaError_t error_code = cudaFree(device_ptr);
         (void)error_code;
         AssertNothrow(error_code == cudaSuccess,
                       dealii::ExcCudaError(cudaGetErrorString(error_code)));
@@ -51,8 +51,9 @@ namespace LinearAlgebra
       Number *
       allocate_device_vector(const std::size_t size)
       {
-        Number *    device_ptr;
-        cudaError_t error_code = cudaMalloc(&device_ptr, size * sizeof(Number));
+        Number *          device_ptr;
+        const cudaError_t error_code =
+          cudaMalloc(&device_ptr, size * sizeof(Number));
         (void)error_code;
         AssertCuda(error_code);
         return device_ptr;
@@ -76,10 +77,10 @@ namespace LinearAlgebra
       , n_elements(V.n_elements)
     {
       // Copy the values.
-      cudaError_t error_code = cudaMemcpy(val.get(),
-                                          V.val.get(),
-                                          n_elements * sizeof(Number),
-                                          cudaMemcpyDeviceToDevice);
+      const cudaError_t error_code = cudaMemcpy(val.get(),
+                                                V.val.get(),
+                                                n_elements * sizeof(Number),
+                                                cudaMemcpyDeviceToDevice);
       AssertCuda(error_code);
     }
 
@@ -90,15 +91,15 @@ namespace LinearAlgebra
     Vector<Number>::operator=(const Vector<Number> &V)
     {
       if (n_elements < V.n_elements)
-        reinit(V.n_elements);
-
-      n_elements = V.n_elements;
+        reinit(V.n_elements, true);
+      else
+        n_elements = V.n_elements;
 
       // Copy the values.
-      cudaError_t error_code = cudaMemcpy(val.get(),
-                                          V.val.get(),
-                                          n_elements * sizeof(Number),
-                                          cudaMemcpyDeviceToDevice);
+      const cudaError_t error_code = cudaMemcpy(val.get(),
+                                                V.val.get(),
+                                                n_elements * sizeof(Number),
+                                                cudaMemcpyDeviceToDevice);
       AssertCuda(error_code);
     }
 
@@ -127,7 +128,8 @@ namespace LinearAlgebra
       // If necessary set the elements to zero
       if (omit_zeroing_entries == false)
         {
-          cudaError_t error_code = cudaMemset(val.get(), 0, n * sizeof(Number));
+          const cudaError_t error_code =
+            cudaMemset(val.get(), 0, n * sizeof(Number));
           AssertCuda(error_code);
         }
       n_elements = n;
@@ -153,10 +155,10 @@ namespace LinearAlgebra
     {
       if (operation == VectorOperation::insert)
         {
-          cudaError_t error_code = cudaMemcpy(val.get(),
-                                              V.begin(),
-                                              n_elements * sizeof(Number),
-                                              cudaMemcpyHostToDevice);
+          const cudaError_t error_code = cudaMemcpy(val.get(),
+                                                    V.begin(),
+                                                    n_elements * sizeof(Number),
+                                                    cudaMemcpyHostToDevice);
           AssertCuda(error_code);
         }
       else if (operation == VectorOperation::add)
@@ -201,7 +203,7 @@ namespace LinearAlgebra
       Assert(s == Number(), ExcMessage("Only 0 can be assigned to a vector."));
       (void)s;
 
-      cudaError_t error_code =
+      const cudaError_t error_code =
         cudaMemset(val.get(), 0, n_elements * sizeof(Number));
       AssertCuda(error_code);
 

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.