15aed82e4SJeremy L Thompson // Copyright (c) 2017-2024, Lawrence Livermore National Security, LLC and other CEED contributors. 26ca0f394SUmesh Unnikrishnan // All Rights Reserved. See the top-level LICENSE and NOTICE files for details. 36ca0f394SUmesh Unnikrishnan // 46ca0f394SUmesh Unnikrishnan // SPDX-License-Identifier: BSD-2-Clause 56ca0f394SUmesh Unnikrishnan // 66ca0f394SUmesh Unnikrishnan // This file is part of CEED: http://github.com/ceed 76ca0f394SUmesh Unnikrishnan 86ca0f394SUmesh Unnikrishnan #include "ceed-sycl-gen.hpp" 96ca0f394SUmesh Unnikrishnan 106ca0f394SUmesh Unnikrishnan #include <ceed/backend.h> 116ca0f394SUmesh Unnikrishnan #include <ceed/ceed.h> 126ca0f394SUmesh Unnikrishnan 136ca0f394SUmesh Unnikrishnan #include <string> 146ca0f394SUmesh Unnikrishnan #include <string_view> 156ca0f394SUmesh Unnikrishnan #include <string.h> 166ca0f394SUmesh Unnikrishnan 176ca0f394SUmesh Unnikrishnan //------------------------------------------------------------------------------ 186ca0f394SUmesh Unnikrishnan // Backend init 196ca0f394SUmesh Unnikrishnan //------------------------------------------------------------------------------ 206ca0f394SUmesh Unnikrishnan static int CeedInit_Sycl_gen(const char *resource, Ceed ceed) { 21dd64fc84SJeremy L Thompson Ceed ceed_shared; 22*097cc795SJames Wright Ceed_Sycl *data; 236ca0f394SUmesh Unnikrishnan char *resource_root; 24dd64fc84SJeremy L Thompson const char fallback_resource[] = "/gpu/sycl/ref"; 25dd64fc84SJeremy L Thompson 266ca0f394SUmesh Unnikrishnan CeedCallBackend(CeedGetResourceRoot(ceed, resource, ":device_id=", &resource_root)); 279d1bceceSJames Wright CeedCheck(!strcmp(resource_root, "/gpu/sycl") || !strcmp(resource_root, "/gpu/sycl/gen"), ceed, CEED_ERROR_BACKEND, 284e3038a5SJeremy L Thompson "Sycl backend cannot use resource: %s", resource); 296ca0f394SUmesh Unnikrishnan CeedCallBackend(CeedFree(&resource_root)); 306ca0f394SUmesh Unnikrishnan 316ca0f394SUmesh Unnikrishnan CeedCallBackend(CeedCalloc(1, &data)); 326ca0f394SUmesh Unnikrishnan CeedCallBackend(CeedSetData(ceed, data)); 336ca0f394SUmesh Unnikrishnan CeedCallBackend(CeedInit_Sycl(ceed, resource)); 346ca0f394SUmesh Unnikrishnan 356ca0f394SUmesh Unnikrishnan CeedCallBackend(CeedInit("/gpu/sycl/shared", &ceed_shared)); 366ca0f394SUmesh Unnikrishnan CeedCallBackend(CeedSetDelegate(ceed, ceed_shared)); 371f4b1b45SUmesh Unnikrishnan CeedCallBackend(CeedSetStream_Sycl(ceed_shared, &(data->sycl_queue))); 386ca0f394SUmesh Unnikrishnan 39ca735530SJeremy L Thompson CeedCallBackend(CeedSetOperatorFallbackResource(ceed, fallback_resource)); 406ca0f394SUmesh Unnikrishnan 411f4b1b45SUmesh Unnikrishnan Ceed ceed_fallback = NULL; 421f4b1b45SUmesh Unnikrishnan CeedCallBackend(CeedGetOperatorFallbackCeed(ceed, &ceed_fallback)); 431f4b1b45SUmesh Unnikrishnan CeedCallBackend(CeedSetStream_Sycl(ceed_fallback, &(data->sycl_queue))); 441f4b1b45SUmesh Unnikrishnan 456ca0f394SUmesh Unnikrishnan CeedCallBackend(CeedSetBackendFunctionCpp(ceed, "Ceed", ceed, "QFunctionCreate", CeedQFunctionCreate_Sycl_gen)); 466ca0f394SUmesh Unnikrishnan CeedCallBackend(CeedSetBackendFunctionCpp(ceed, "Ceed", ceed, "OperatorCreate", CeedOperatorCreate_Sycl_gen)); 476ca0f394SUmesh Unnikrishnan CeedCallBackend(CeedSetBackendFunctionCpp(ceed, "Ceed", ceed, "Destroy", CeedDestroy_Sycl)); 486ca0f394SUmesh Unnikrishnan return CEED_ERROR_SUCCESS; 496ca0f394SUmesh Unnikrishnan } 506ca0f394SUmesh Unnikrishnan 516ca0f394SUmesh Unnikrishnan //------------------------------------------------------------------------------ 526ca0f394SUmesh Unnikrishnan // Register backend 536ca0f394SUmesh Unnikrishnan //------------------------------------------------------------------------------ 546ca0f394SUmesh Unnikrishnan CEED_INTERN int CeedRegister_Sycl_Gen(void) { return CeedRegister("/gpu/sycl/gen", CeedInit_Sycl_gen, 20); } 556ca0f394SUmesh Unnikrishnan 566ca0f394SUmesh Unnikrishnan //------------------------------------------------------------------------------ 57