Commits

Karl Rupp  committed 1fc5b51

ViennaCL: Fixed unused variable and function warnings.

This was mostly due to a poor handling of option parsing.
The two old functions
ViennaCLSetFromOptions
VecSetFromOptions_SeqViennaCL
were refactored:
- VecSetFromOptions_SeqViennaCL was completely removed, as it only forwarded.
- ViennaCLSetFromOptions was renamed to PetscObjectSetFromOptions_ViennaCL
for better accordance with the PETSc naming scheme (thanks to Jed for pointing this out)
The options are now checked right before the respective objects are instantiated,
thus delaying the OpenCL setup as long as possible.

  • Participants
  • Parent commits 4ca9bf2

Comments (0)

Files changed (6)

File src/mat/impls/aij/mpi/mpiviennacl/mpiaijviennacl.cxx

 {
   Mat_MPIAIJ *b = (Mat_MPIAIJ*)B->data;
   PetscErrorCode ierr;
-  PetscInt       i;
 
   PetscFunctionBegin;
   ierr = PetscLayoutSetUp(B->rmap);CHKERRQ(ierr);
   ierr = PetscObjectComposeFunction((PetscObject)A,"MatMPIAIJSetPreallocation_C",MatMPIAIJSetPreallocation_MPIAIJViennaCL);CHKERRQ(ierr);
   A->ops->getvecs        = MatGetVecs_MPIAIJViennaCL;
 
-  ierr = MatSetFromOptions_SeqViennaCL(A);CHKERRQ(ierr); /* Allows to set device type before allocating any objects */
   ierr = PetscObjectChangeTypeName((PetscObject)A,MATMPIAIJVIENNACL);CHKERRQ(ierr);
   PetscFunctionReturn(0);
 }

File src/mat/impls/aij/seq/seqviennacl/aijviennacl.cxx

       ierr = PetscLogEventBegin(MAT_ViennaCLCopyToGPU,A,0,0,0);CHKERRQ(ierr);
 
       try {
+        ierr = PetscObjectSetFromOptions_ViennaCL((PetscObject)A);CHKERRQ(ierr); /* Allows to set device type before allocating any objects */
         viennaclstruct->mat = new ViennaCLAIJMatrix();
         if (a->compressedrow.use) {
           ii = a->compressedrow.i;
   B->ops->destroy        = MatDestroy_SeqAIJViennaCL;
   B->ops->getvecs        = MatGetVecs_SeqAIJViennaCL;
 
-  ierr = MatSetFromOptions_SeqViennaCL(B);CHKERRQ(ierr); /* Allows to set device type before allocating any objects */
   ierr = PetscObjectChangeTypeName((PetscObject)B,MATSEQAIJVIENNACL);CHKERRQ(ierr);
 
   B->valid_GPU_matrix = PETSC_VIENNACL_UNALLOCATED;

File src/mat/impls/aij/seq/seqviennacl/viennaclmatimpl.h

   ViennaCLAIJMatrix      *mat;  /* pointer to the matrix on the GPU */
 };
 
-#undef __FUNCT__
-#define __FUNCT__ "MatSetFromOptions_SeqViennaCL"
-static PetscErrorCode MatSetFromOptions_SeqViennaCL(Mat A)
-{
-  PetscErrorCode       ierr;
-  PetscBool            flg;
-
-  PetscFunctionBegin;
-  ViennaCLSetFromOptions((PetscObject)A);
-  PetscFunctionReturn(0);
-}
-
 PETSC_INTERN PetscErrorCode MatViennaCLCopyToGPU(Mat);
 PETSC_INTERN PetscErrorCode MatViennaCLCopyFromGPU(Mat, ViennaCLAIJMatrix*);
 #endif

File src/vec/vec/impls/mpi/mpiviennacl/mpiviennacl.cxx

      reset array?
      get values?
   */
-  ierr = VecSetFromOptions_SeqViennaCL(vv);CHKERRQ(ierr); /* Allows to set device type before allocating any objects */
   ierr = VecViennaCLAllocateCheck(vv);CHKERRQ(ierr);
   vv->valid_GPU_array      = PETSC_VIENNACL_GPU;
   ierr = VecSet(vv,0.0);CHKERRQ(ierr);

File src/vec/vec/impls/seq/seqviennacl/vecviennacl.cxx

 #include "viennacl/ocl/backend.hpp"
 
 #undef __FUNCT__
+#define __FUNCT__ "PetscObjectSetFromOptions_ViennaCL"
+PETSC_EXTERN PetscErrorCode PetscObjectSetFromOptions_ViennaCL(PetscObject obj)
+{
+  PetscErrorCode       ierr;
+  PetscBool            flg;
+
+  PetscFunctionBegin;
+  ierr = PetscObjectOptionsBegin(obj);
+
+  ierr = PetscOptionsHasName(NULL,"-viennacl_device_cpu",&flg);CHKERRQ(ierr);
+  if (flg) {
+    try {
+      viennacl::ocl::set_context_device_type(0, CL_DEVICE_TYPE_CPU);
+    } catch (std::exception const & ex) {
+      SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"ViennaCL error: %s", ex.what());
+    }
+  }
+  ierr = PetscOptionsHasName(NULL,"-viennacl_device_gpu",&flg);CHKERRQ(ierr);
+  if (flg) {
+    try {
+      viennacl::ocl::set_context_device_type(0, CL_DEVICE_TYPE_GPU);
+    } catch (std::exception const & ex) {
+      SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"ViennaCL error: %s", ex.what());
+    }
+  }
+  ierr = PetscOptionsHasName(NULL,"-viennacl_device_accelerator",&flg);CHKERRQ(ierr);
+  if (flg) {
+    try {
+      viennacl::ocl::set_context_device_type(0, CL_DEVICE_TYPE_ACCELERATOR);
+    } catch (std::exception const & ex) {
+      SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"ViennaCL error: %s", ex.what());
+    }
+  }
+
+  ierr = PetscOptionsEnd();CHKERRQ(ierr);
+  PetscFunctionReturn(0);
+}
+
+#undef __FUNCT__
 #define __FUNCT__ "VecViennaCLAllocateCheckHost"
 /*
     Allocates space for the vector array on the Host if it does not exist.
   // First allocate memory on the GPU if needed
   if (!v->spptr) {
     try {
+      ierr = PetscObjectSetFromOptions_ViennaCL((PetscObject)v);CHKERRQ(ierr);
       v->spptr                            = new Vec_ViennaCL;
       ((Vec_ViennaCL*)v->spptr)->GPUarray = new ViennaCLVector((PetscBLASInt)v->map->n);
 
   V->ops->destroy         = VecDestroy_SeqViennaCL;
   V->ops->duplicate       = VecDuplicate_SeqViennaCL;
 
-  ierr = VecSetFromOptions_SeqViennaCL(V);CHKERRQ(ierr); /* Allows to set device type before allocating any objects */
   ierr = VecViennaCLAllocateCheck(V);CHKERRQ(ierr);
   V->valid_GPU_array      = PETSC_VIENNACL_GPU;
   ierr = VecSet(V,0.0);CHKERRQ(ierr);

File src/vec/vec/impls/seq/seqviennacl/viennaclvecimpl.h

 
 typedef viennacl::vector<PetscScalar>    ViennaCLVector;
 
+PETSC_EXTERN PetscErrorCode PetscObjectSetFromOptions_ViennaCL(PetscObject obj);
 
 PETSC_INTERN PetscErrorCode VecDotNorm2_SeqViennaCL(Vec,Vec,PetscScalar*, PetscScalar*);
 PETSC_INTERN PetscErrorCode VecPointwiseDivide_SeqViennaCL(Vec,Vec,Vec);
 
 
 #undef __FUNCT__
-#define __FUNCT__ "ViennaCLSetFromOptions"
-static PetscErrorCode ViennaCLSetFromOptions(PetscObject obj)
-{
-  PetscErrorCode       ierr;
-  PetscBool            flg;
-
-  PetscFunctionBegin;
-  ierr = PetscObjectOptionsBegin(obj);
-
-  ierr = PetscOptionsHasName(NULL,"-viennacl_device_cpu",&flg);CHKERRQ(ierr);
-  if (flg) {
-    try {
-      viennacl::ocl::set_context_device_type(0, CL_DEVICE_TYPE_CPU);
-    } catch (std::exception const & ex) {
-      SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"ViennaCL error: %s", ex.what());
-    }
-  }
-  ierr = PetscOptionsHasName(NULL,"-viennacl_device_gpu",&flg);CHKERRQ(ierr);
-  if (flg) {
-    try {
-      viennacl::ocl::set_context_device_type(0, CL_DEVICE_TYPE_GPU);
-    } catch (std::exception const & ex) {
-      SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"ViennaCL error: %s", ex.what());
-    }
-  }
-  ierr = PetscOptionsHasName(NULL,"-viennacl_device_accelerator",&flg);CHKERRQ(ierr);
-  if (flg) {
-    try {
-      viennacl::ocl::set_context_device_type(0, CL_DEVICE_TYPE_ACCELERATOR);
-    } catch (std::exception const & ex) {
-      SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"ViennaCL error: %s", ex.what());
-    }
-  }
-
-  ierr = PetscOptionsEnd();CHKERRQ(ierr);
-  PetscFunctionReturn(0);
-}
-
-
-#undef __FUNCT__
-#define __FUNCT__ "VecSetFromOptions_SeqViennaCL"
-static PetscErrorCode VecSetFromOptions_SeqViennaCL(Vec v)
-{
-  PetscErrorCode       ierr;
-  PetscBool            flg;
-
-  PetscFunctionBegin;
-  ViennaCLSetFromOptions((PetscObject)v);
-  PetscFunctionReturn(0);
-}
-
-#undef __FUNCT__
 #define __FUNCT__ "VecViennaCLGetArrayReadWrite"
 PETSC_STATIC_INLINE PetscErrorCode VecViennaCLGetArrayReadWrite(Vec v, ViennaCLVector **a)
 {