Skip to content

Commit bcb0187

Browse files
authored
Merge pull request #733 from CEED/jeremy/more-registration
Extra error message for uncompiled backends
2 parents 8b2d6f4 + 8725033 commit bcb0187

7 files changed

Lines changed: 74 additions & 40 deletions

File tree

backends/ceed-backend-list.h

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,24 @@
55
// listed, and also to define weak symbol aliases for backends that are not
66
// configured.
77

8-
MACRO(CeedRegister_Avx_Blocked)
9-
MACRO(CeedRegister_Avx_Serial)
10-
MACRO(CeedRegister_Cuda)
11-
MACRO(CeedRegister_Cuda_Gen)
12-
MACRO(CeedRegister_Cuda_Shared)
13-
MACRO(CeedRegister_Hip)
14-
MACRO(CeedRegister_Hip_Gen)
15-
MACRO(CeedRegister_Hip_Shared)
16-
MACRO(CeedRegister_Magma)
17-
MACRO(CeedRegister_Magma_Det)
18-
MACRO(CeedRegister_Memcheck_Blocked)
19-
MACRO(CeedRegister_Memcheck_Serial)
20-
MACRO(CeedRegister_Occa)
21-
MACRO(CeedRegister_Opt_Blocked)
22-
MACRO(CeedRegister_Opt_Serial)
23-
MACRO(CeedRegister_Ref)
24-
MACRO(CeedRegister_Ref_Blocked)
25-
MACRO(CeedRegister_Tmpl)
26-
MACRO(CeedRegister_Tmpl_Sub)
27-
MACRO(CeedRegister_Xsmm_Blocked)
28-
MACRO(CeedRegister_Xsmm_Serial)
8+
MACRO(CeedRegister_Avx_Blocked, 1, "/cpu/self/avx/blocked")
9+
MACRO(CeedRegister_Avx_Serial, 1, "/cpu/self/avx/serial")
10+
MACRO(CeedRegister_Cuda, 1, "/gpu/cuda/ref")
11+
MACRO(CeedRegister_Cuda_Gen, 1, "/gpu/cuda/gen")
12+
MACRO(CeedRegister_Cuda_Shared, 1, "/gpu/cuda/shared")
13+
MACRO(CeedRegister_Hip, 1, "/gpu/hip/ref")
14+
MACRO(CeedRegister_Hip_Gen, 1, "/gpu/hip/gen")
15+
MACRO(CeedRegister_Hip_Shared, 1, "/gpu/hip/shared")
16+
MACRO(CeedRegister_Magma, 2, "/gpu/cuda/magma", "/gpu/hip/magma")
17+
MACRO(CeedRegister_Magma_Det, 2, "/gpu/cuda/magma/det", "/gpu/hip/magma/det")
18+
MACRO(CeedRegister_Memcheck_Blocked, 1, "/cpu/self/memcheck/blocked")
19+
MACRO(CeedRegister_Memcheck_Serial, 1, "/cpu/self/memcheck/serial")
20+
MACRO(CeedRegister_Occa, 4, "/cpu/self/occa", "/cpu/openmp/occa", "/gpu/hip/occa", "/gpu/cuda/occa")
21+
MACRO(CeedRegister_Opt_Blocked, 1, "/cpu/self/opt/blocked")
22+
MACRO(CeedRegister_Opt_Serial, 1, "/cpu/self/opt/serial")
23+
MACRO(CeedRegister_Ref, 1, "/cpu/self/ref/serial")
24+
MACRO(CeedRegister_Ref_Blocked, 1, "/cpu/self/ref/blocked")
25+
MACRO(CeedRegister_Tmpl, 1, "/cpu/self/tmpl")
26+
MACRO(CeedRegister_Tmpl_Sub, 1, "/cpu/self/tmpl/sub")
27+
MACRO(CeedRegister_Xsmm_Blocked, 1, "/cpu/self/xsmm/blocked")
28+
MACRO(CeedRegister_Xsmm_Serial, 1, "/cpu/self/xsmm/serial")

backends/ceed-backend-weak.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,33 @@
22
#include <stdlib.h>
33
#include <stdio.h>
44

5-
// This function provides a debug target for weak symbols
65
// LCOV_EXCL_START
7-
static int CeedRegister_Weak(const char *name) {
6+
// This function provides improved error messages for uncompiled backends
7+
static int CeedInit_Weak(const char *resource, Ceed ceed) {
8+
return CeedError(ceed, CEED_ERROR_UNSUPPORTED,
9+
"Backend not currently compiled: %s\n"
10+
"Consult the installation instructions to compile this backend",
11+
resource);
12+
}
13+
14+
// This function provides a debug target for weak symbols
15+
static int CeedRegister_Weak(const char *name, int num_prefixes, ...) {
816
if (getenv("CEED_DEBUG")) fprintf(stderr, "Weak %s\n", name);
17+
18+
va_list prefixes;
19+
va_start(prefixes, num_prefixes);
20+
int ierr;
21+
for (int i=0; i<num_prefixes; i++) {
22+
ierr = CeedRegister(va_arg(prefixes, const char*), CeedInit_Weak, CEED_MAX_BACKEND_PRIORITY);
23+
CeedChk(ierr);
24+
}
25+
va_end(prefixes);
926
return CEED_ERROR_SUCCESS;
1027
}
1128
// LCOV_EXCL_STOP
1229

13-
#define MACRO(name) \
30+
#define MACRO(name,num_prefixes, ...) \
1431
CEED_INTERN int name(void) __attribute__((weak)); \
15-
int name(void) { return CeedRegister_Weak(__func__); }
32+
int name(void) { return CeedRegister_Weak(__func__,num_prefixes, ## __VA_ARGS__); }
1633
#include "ceed-backend-list.h"
1734
#undef MACRO

include/ceed/backend.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@
2020
#define _ceed_backend_h
2121

2222
#include <ceed/ceed.h>
23+
#include <limits.h>
2324
#include <stdbool.h>
2425

2526
#define CEED_INTERN CEED_EXTERN __attribute__((visibility ("hidden")))
2627
#define CEED_UNUSED __attribute__((unused))
2728

2829
#define CEED_MAX_RESOURCE_LEN 1024
30+
#define CEED_MAX_BACKEND_PRIORITY UINT_MAX
2931
#define CEED_ALIGN 64
3032
#define CEED_COMPOSITE_MAX 16
3133
#define CEED_EPSILON 1E-16

interface/ceed-register.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
static bool register_all_called;
88

9-
#define MACRO(name) CEED_INTERN int name(void);
9+
#define MACRO(name,...) CEED_INTERN int name(void);
1010
#include "../backends/ceed-backend-list.h"
1111
#undef MACRO
1212

@@ -26,7 +26,7 @@ int CeedRegisterAll() {
2626
if (register_all_called) return 0;
2727
register_all_called = true;
2828

29-
#define MACRO(name) CeedChk(name());
29+
#define MACRO(name,...) CeedChk(name());
3030
#include "../backends/ceed-backend-list.h"
3131
#undef MACRO
3232
return CEED_ERROR_SUCCESS;

interface/ceed.c

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -595,12 +595,12 @@ int CeedSetData(Ceed ceed, void *data) {
595595
/// @{
596596

597597
/**
598-
@brief Get the list of avaliable resource names for Ceed contexts
598+
@brief Get the list of available resource names for Ceed contexts
599599
Note: The caller is responsible for `free()`ing the resources and priorities arrays,
600600
but should not `free()` the contents of the resources array.
601601
602-
@param[out] n Number of avaliable resources
603-
@param[out] resources List of avaliable resource names
602+
@param[out] n Number of available resources
603+
@param[out] resources List of available resource names
604604
@param[out] priorities Resource name prioritization values, lower is better
605605
606606
@return An error code: 0 - success, otherwise - failure
@@ -610,7 +610,7 @@ int CeedSetData(Ceed ceed, void *data) {
610610
// LCOV_EXCL_START
611611
int CeedRegistryGetList(size_t *n, char ***const resources,
612612
CeedInt **priorities) {
613-
*n = num_backends;
613+
*n = 0;
614614
*resources = malloc(num_backends * sizeof(**resources));
615615
if (!resources)
616616
return CeedError(NULL, CEED_ERROR_MAJOR, "malloc() failure");
@@ -620,8 +620,20 @@ int CeedRegistryGetList(size_t *n, char ***const resources,
620620
return CeedError(NULL, CEED_ERROR_MAJOR, "malloc() failure");
621621
}
622622
for (size_t i=0; i<num_backends; i++) {
623-
*resources[i] = backends[i].prefix;
624-
if (priorities) *priorities[i] = backends[i].priority;
623+
// Only report compiled backends
624+
if (backends[i].priority < CEED_MAX_BACKEND_PRIORITY) {
625+
*resources[i] = backends[i].prefix;
626+
if (priorities) *priorities[i] = backends[i].priority;
627+
*n += 1;
628+
}
629+
}
630+
*resources = realloc(*resources, *n * sizeof(**resources));
631+
if (!resources)
632+
return CeedError(NULL, CEED_ERROR_MAJOR, "realloc() failure");
633+
if (priorities) {
634+
*priorities = realloc(*priorities, *n * sizeof(**priorities));
635+
if (!priorities)
636+
return CeedError(NULL, CEED_ERROR_MAJOR, "realloc() failure");
625637
}
626638
return CEED_ERROR_SUCCESS;
627639
};
@@ -631,7 +643,7 @@ int CeedRegistryGetList(size_t *n, char ***const resources,
631643
@brief Initialize a \ref Ceed context to use the specified resource.
632644
Note: Prefixing the resource with "help:" (e.g. "help:/cpu/self")
633645
will result in CeedInt printing the current libCEED version number
634-
and a list of current avaliable backend resources to stderr.
646+
and a list of current available backend resources to stderr.
635647
636648
@param resource Resource to use, e.g., "/cpu/self"
637649
@param ceed The library context
@@ -643,7 +655,8 @@ int CeedRegistryGetList(size_t *n, char ***const resources,
643655
**/
644656
int CeedInit(const char *resource, Ceed *ceed) {
645657
int ierr;
646-
size_t match_len = 0, match_idx = UINT_MAX, match_priority = UINT_MAX, priority;
658+
size_t match_len = 0, match_idx = UINT_MAX,
659+
match_priority = CEED_MAX_BACKEND_PRIORITY, priority;
647660

648661
// Find matching backend
649662
if (!resource)
@@ -661,9 +674,11 @@ int CeedInit(const char *resource, Ceed *ceed) {
661674
fprintf(stderr, "libCEED version: %d.%d%d%s\n", CEED_VERSION_MAJOR,
662675
CEED_VERSION_MINOR, CEED_VERSION_PATCH,
663676
CEED_VERSION_RELEASE ? "" : "+development");
664-
fprintf(stderr, "Avaliable backend resources:\n");
677+
fprintf(stderr, "Available backend resources:\n");
665678
for (size_t i=0; i<num_backends; i++) {
666-
fprintf(stderr, " %s\n", backends[i].prefix);
679+
// Only report compiled backends
680+
if (backends[i].priority < CEED_MAX_BACKEND_PRIORITY)
681+
fprintf(stderr, " %s\n", backends[i].prefix);
667682
}
668683
fflush(stderr);
669684
match_help = 5; // Delineating character expected
@@ -694,7 +709,7 @@ int CeedInit(const char *resource, Ceed *ceed) {
694709
// LCOV_EXCL_STOP
695710
} else if (match_len != stem_length) {
696711
// LCOV_EXCL_START
697-
return CeedError(NULL, CEED_ERROR_MAJOR, "No suitable backend: %s "
712+
return CeedError(NULL, CEED_ERROR_MAJOR, "No suitable backend: %s\n"
698713
"Closest match: %s", resource, backends[match_idx].prefix);
699714
// LCOV_EXCL_STOP
700715
}

tests/junit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def run(test, backends):
101101
if test[:4] in 't006 t007'.split():
102102
check_required_failure(case, proc.stderr, 'No suitable backend:')
103103
if test[:4] in 't008'.split():
104-
check_required_failure(case, proc.stderr, 'Avaliable backend resources:')
104+
check_required_failure(case, proc.stderr, 'Available backend resources:')
105105
if test[:4] in 't110 t111 t112 t113 t114'.split():
106106
check_required_failure(case, proc.stderr, 'Cannot grant CeedVector array access')
107107
if test[:4] in 't115'.split():

tests/tap.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ for ((i=0;i<${#backends[@]};++i)); do
134134
fi
135135

136136
# grep to pass test t008 on output in stderr
137-
if grep -F -q -e 'Avaliable backend resources:' ${output}.err \
137+
if grep -F -q -e 'Available backend resources:' ${output}.err \
138138
&& [[ "$1" = "t008"* ]] ; then
139139
printf "ok $i0 PASS - expected failure $1 $backend\n"
140140
printf "ok $i1 PASS - expected failure $1 $backend stdout\n"

0 commit comments

Comments
 (0)