xref: /libCEED/rust/libceed-sys/c-src/backends/opt/ceed-opt-serial.c (revision 49aac155e7a09736f56fb3abac0f57dab29f7cbf)
13d8e8822SJeremy L Thompson // Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other CEED contributors.
23d8e8822SJeremy L Thompson // All Rights Reserved. See the top-level LICENSE and NOTICE files for details.
389c6efa4Sjeremylt //
43d8e8822SJeremy L Thompson // SPDX-License-Identifier: BSD-2-Clause
589c6efa4Sjeremylt //
63d8e8822SJeremy L Thompson // This file is part of CEED:  http://github.com/ceed
789c6efa4Sjeremylt 
8*49aac155SJeremy L Thompson #include <ceed.h>
9ec3da8bcSJed Brown #include <ceed/backend.h>
103d576824SJeremy L Thompson #include <stdbool.h>
1189c6efa4Sjeremylt #include <string.h>
122b730f8bSJeremy L Thompson 
1389c6efa4Sjeremylt #include "ceed-opt.h"
1489c6efa4Sjeremylt 
15f10650afSjeremylt //------------------------------------------------------------------------------
16f10650afSjeremylt // Backend Destroy
17f10650afSjeremylt //------------------------------------------------------------------------------
1889c6efa4Sjeremylt static int CeedDestroy_Opt(Ceed ceed) {
1989c6efa4Sjeremylt   Ceed_Opt *data;
202b730f8bSJeremy L Thompson   CeedCallBackend(CeedGetData(ceed, &data));
212b730f8bSJeremy L Thompson   CeedCallBackend(CeedFree(&data));
2289c6efa4Sjeremylt 
23e15f9bd0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
2489c6efa4Sjeremylt }
2589c6efa4Sjeremylt 
26f10650afSjeremylt //------------------------------------------------------------------------------
27f10650afSjeremylt // Backend Init
28f10650afSjeremylt //------------------------------------------------------------------------------
2989c6efa4Sjeremylt static int CeedInit_Opt_Serial(const char *resource, Ceed ceed) {
302b730f8bSJeremy L Thompson   if (strcmp(resource, "/cpu/self") && strcmp(resource, "/cpu/self/opt/serial")) {
31c042f62fSJeremy L Thompson     // LCOV_EXCL_START
322b730f8bSJeremy L Thompson     return CeedError(ceed, CEED_ERROR_BACKEND, "Opt backend cannot use resource: %s", resource);
33c042f62fSJeremy L Thompson     // LCOV_EXCL_STOP
342b730f8bSJeremy L Thompson   }
352b730f8bSJeremy L Thompson   CeedCallBackend(CeedSetDeterministic(ceed, true));
3689c6efa4Sjeremylt 
37ea61e9acSJeremy L Thompson   // Create reference Ceed that implementation will be dispatched through unless overridden
38ea61e9acSJeremy L Thompson 
39d1d35e2fSjeremylt   Ceed ceed_ref;
402b730f8bSJeremy L Thompson   CeedCallBackend(CeedInit("/cpu/self/ref/serial", &ceed_ref));
412b730f8bSJeremy L Thompson   CeedCallBackend(CeedSetDelegate(ceed, ceed_ref));
4289c6efa4Sjeremylt 
43ea61e9acSJeremy L Thompson   // Set fallback Ceed resource for advanced operator functionality
44e2f04181SAndrew T. Barker   const char fallbackresource[] = "/cpu/self/ref/serial";
452b730f8bSJeremy L Thompson   CeedCallBackend(CeedSetOperatorFallbackResource(ceed, fallbackresource));
46e2f04181SAndrew T. Barker 
472b730f8bSJeremy L Thompson   CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "Destroy", CeedDestroy_Opt));
482b730f8bSJeremy L Thompson   CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "TensorContractCreate", CeedTensorContractCreate_Opt));
492b730f8bSJeremy L Thompson   CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "OperatorCreate", CeedOperatorCreate_Opt));
5089c6efa4Sjeremylt 
5189c6efa4Sjeremylt   // Set blocksize
5289c6efa4Sjeremylt   Ceed_Opt *data;
532b730f8bSJeremy L Thompson   CeedCallBackend(CeedCalloc(1, &data));
54d1d35e2fSjeremylt   data->blk_size = 1;
552b730f8bSJeremy L Thompson   CeedCallBackend(CeedSetData(ceed, data));
5689c6efa4Sjeremylt 
57e15f9bd0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
5889c6efa4Sjeremylt }
5989c6efa4Sjeremylt 
60f10650afSjeremylt //------------------------------------------------------------------------------
61f10650afSjeremylt // Backend Register
62f10650afSjeremylt //------------------------------------------------------------------------------
632b730f8bSJeremy L Thompson CEED_INTERN int CeedRegister_Opt_Serial(void) { return CeedRegister("/cpu/self/opt/serial", CeedInit_Opt_Serial, 45); }
641d013790SJed Brown 
65f10650afSjeremylt //------------------------------------------------------------------------------
66