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 8ec3da8bcSJed Brown #include <ceed/backend.h> 92b730f8bSJeremy L Thompson #include <ceed/ceed.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_Blocked(const char *resource, Ceed ceed) { 302b730f8bSJeremy L Thompson if (strcmp(resource, "/cpu/self") && strcmp(resource, "/cpu/self/opt") && strcmp(resource, "/cpu/self/opt/blocked")) { 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 37*ea61e9acSJeremy L Thompson // Create reference Ceed that implementation will be dispatched through unless overridden 38*ea61e9acSJeremy 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 43*ea61e9acSJeremy 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, "OperatorCreate", CeedOperatorCreate_Opt)); 4989c6efa4Sjeremylt 5089c6efa4Sjeremylt // Set blocksize 5189c6efa4Sjeremylt Ceed_Opt *data; 522b730f8bSJeremy L Thompson CeedCallBackend(CeedCalloc(1, &data)); 53d1d35e2fSjeremylt data->blk_size = 8; 542b730f8bSJeremy L Thompson CeedCallBackend(CeedSetData(ceed, data)); 5589c6efa4Sjeremylt 56e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 5789c6efa4Sjeremylt } 5889c6efa4Sjeremylt 59f10650afSjeremylt //------------------------------------------------------------------------------ 60f10650afSjeremylt // Backend Register 61f10650afSjeremylt //------------------------------------------------------------------------------ 622b730f8bSJeremy L Thompson CEED_INTERN int CeedRegister_Opt_Blocked(void) { return CeedRegister("/cpu/self/opt/blocked", CeedInit_Opt_Blocked, 40); } 63f10650afSjeremylt //------------------------------------------------------------------------------ 64