Actual source code: ex217.c
1: static char help[] = "Tests MatGetCurrentMemType for gpu type matrices both bound and unbound to cpu";
3: #include <petscmat.h>
4: #include <../src/mat/impls/aij/mpi/mpiaij.h>
6: int main(int argc, char **argv)
7: {
8: Mat A;
9: PetscMemType memtype;
10: MatType mattype;
11: PetscBool ishypre, iskokkos, iscuda, iship;
13: PetscFunctionBeginUser;
14: PetscCall(PetscInitialize(&argc, &argv, NULL, help));
15: PetscCall(MatCreate(PETSC_COMM_WORLD, &A));
16: PetscCall(MatSetSizes(A, PETSC_DECIDE, PETSC_DECIDE, 1, 1));
17: PetscCall(MatSetFromOptions(A));
18: PetscCall(MatGetType(A, &mattype));
19: PetscCall(PetscObjectTypeCompareAny((PetscObject)A, &iscuda, MATMPIAIJCUSPARSE, MATSEQAIJCUSPARSE, MATSEQDENSECUDA, MATMPIDENSECUDA, ""));
20: PetscCall(PetscObjectTypeCompareAny((PetscObject)A, &iship, MATMPIAIJHIPSPARSE, MATSEQAIJHIPSPARSE, MATSEQDENSEHIP, MATMPIDENSEHIP, ""));
21: PetscCall(PetscObjectTypeCompareAny((PetscObject)A, &iskokkos, MATMPIAIJKOKKOS, MATSEQAIJKOKKOS, ""));
22: PetscCall(PetscObjectTypeCompare((PetscObject)A, MATHYPRE, &ishypre));
23: #if PetscDefined(HAVE_HYPRE)
24: PetscCall(MatHYPRESetPreallocation(A, 1, NULL, 1, NULL));
25: #endif
26: PetscCall(MatSeqAIJSetPreallocation(A, 1, NULL));
27: PetscCall(MatMPIAIJSetPreallocation(A, 1, NULL, 1, NULL));
28: PetscCall(MatSetUp(A));
30: PetscCall(MatGetCurrentMemType(A, &memtype));
31: if (iscuda) PetscCheck(memtype == PETSC_MEMTYPE_CUDA, PETSC_COMM_WORLD, PETSC_ERR_PLIB, "wrong memory type");
32: else if (iship) PetscCheck(memtype == PETSC_MEMTYPE_HIP, PETSC_COMM_WORLD, PETSC_ERR_PLIB, "wrong memory type");
33: else if (iskokkos) PetscCheck(memtype == PETSC_MEMTYPE_KOKKOS, PETSC_COMM_WORLD, PETSC_ERR_PLIB, "wrong memory type");
34: else if (ishypre) PetscCheck(PetscDefined(HAVE_HYPRE_DEVICE) ? memtype == PETSC_MEMTYPE_DEVICE : memtype == PETSC_MEMTYPE_HOST, PETSC_COMM_WORLD, PETSC_ERR_PLIB, "wrong memory type");
35: else PetscCheck(memtype == PETSC_MEMTYPE_HOST, PETSC_COMM_WORLD, PETSC_ERR_PLIB, "wrong memory type");
37: // Kokkos doesn't currently implement MatBindToCPU
38: if (!iskokkos) {
39: PetscCall(MatBindToCPU(A, PETSC_TRUE));
40: PetscCall(MatGetCurrentMemType(A, &memtype));
41: PetscCheck(memtype == PETSC_MEMTYPE_HOST, PETSC_COMM_WORLD, PETSC_ERR_PLIB, "wrong memory type");
42: }
43: PetscCall(MatDestroy(&A));
44: PetscCall(PetscFinalize());
45: return 0;
46: }
48: /*TEST
50: testset:
51: nsize: {{1 2}}
52: output_file: output/empty.out
54: test:
55: suffix: dense
56: args: -mat_type dense
58: test:
59: requires: cuda
60: suffix: densecuda
61: args: -mat_type densecuda
63: test:
64: requires: hip
65: suffix: densehip
66: args: -mat_type densehip
68: test:
69: suffix: seqaij
70: args: -mat_type aij
71: output_file: output/empty.out
73: test:
74: suffix: mpiaij
75: nsize: 2
76: args: -mat_type aij
77: output_file: output/empty.out
79: test:
80: requires: cuda
81: suffix: seqaijcusparse
82: args: -mat_type aijcusparse
83: output_file: output/empty.out
85: test:
86: requires: cuda
87: suffix: mpiaijcusparse
88: nsize: 2
89: args: -mat_type aijcusparse
90: output_file: output/empty.out
92: test:
93: requires: hip
94: suffix: seqaijhipsparse
95: args: -mat_type aijhipsparse
96: output_file: output/empty.out
98: test:
99: requires: hip
100: suffix: mpiaijhipsparse
101: nsize: 2
102: args: -mat_type aijhipsparse
103: output_file: output/empty.out
105: test:
106: requires: kokkos_kernels
107: suffix: seqaijkokkos
108: args: -mat_type aijkokkos
109: output_file: output/empty.out
111: test:
112: requires: kokkos_kernels
113: suffix: mpiaijkokkos
114: nsize: 2
115: args: -mat_type aijkokkos
116: output_file: output/empty.out
118: test:
119: requires: hypre
120: suffix: hypre
121: args: -mat_type hypre
122: output_file: output/empty.out
124: test:
125: requires: hypre
126: suffix: hypre_parallel
127: nsize: 2
128: args: -mat_type hypre
129: output_file: output/empty.out
131: TEST*/