1*9ba83ac0SJeremy L Thompson // Copyright (c) 2017-2026, 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) { 2146b50f9eSZach Atkins Ceed ceed_shared, ceed_ref; 22097cc795SJames Wright Ceed_Sycl *data; 236ca0f394SUmesh Unnikrishnan char *resource_root; 24dd64fc84SJeremy L Thompson 256ca0f394SUmesh Unnikrishnan CeedCallBackend(CeedGetResourceRoot(ceed, resource, ":device_id=", &resource_root)); 269d1bceceSJames Wright CeedCheck(!strcmp(resource_root, "/gpu/sycl") || !strcmp(resource_root, "/gpu/sycl/gen"), ceed, CEED_ERROR_BACKEND, 274e3038a5SJeremy L Thompson "Sycl backend cannot use resource: %s", resource); 286ca0f394SUmesh Unnikrishnan CeedCallBackend(CeedFree(&resource_root)); 296ca0f394SUmesh Unnikrishnan 306ca0f394SUmesh Unnikrishnan CeedCallBackend(CeedCalloc(1, &data)); 316ca0f394SUmesh Unnikrishnan CeedCallBackend(CeedSetData(ceed, data)); 326ca0f394SUmesh Unnikrishnan CeedCallBackend(CeedInit_Sycl(ceed, resource)); 336ca0f394SUmesh Unnikrishnan 346ca0f394SUmesh Unnikrishnan CeedCallBackend(CeedInit("/gpu/sycl/shared", &ceed_shared)); 356ca0f394SUmesh Unnikrishnan CeedCallBackend(CeedSetDelegate(ceed, ceed_shared)); 361f4b1b45SUmesh Unnikrishnan CeedCallBackend(CeedSetStream_Sycl(ceed_shared, &(data->sycl_queue))); 379bc66399SJeremy L Thompson CeedCallBackend(CeedDestroy(&ceed_shared)); 386ca0f394SUmesh Unnikrishnan 3946b50f9eSZach Atkins CeedCallBackend(CeedInit("/gpu/sycl/ref", &ceed_ref)); 4046b50f9eSZach Atkins CeedCallBackend(CeedSetOperatorFallbackCeed(ceed, ceed_ref)); 4146b50f9eSZach Atkins CeedCallBackend(CeedSetStream_Sycl(ceed_ref, &(data->sycl_queue))); 4246b50f9eSZach Atkins CeedCallBackend(CeedDestroy(&ceed_ref)); 431f4b1b45SUmesh Unnikrishnan 446ca0f394SUmesh Unnikrishnan CeedCallBackend(CeedSetBackendFunctionCpp(ceed, "Ceed", ceed, "QFunctionCreate", CeedQFunctionCreate_Sycl_gen)); 456ca0f394SUmesh Unnikrishnan CeedCallBackend(CeedSetBackendFunctionCpp(ceed, "Ceed", ceed, "OperatorCreate", CeedOperatorCreate_Sycl_gen)); 466ca0f394SUmesh Unnikrishnan CeedCallBackend(CeedSetBackendFunctionCpp(ceed, "Ceed", ceed, "Destroy", CeedDestroy_Sycl)); 476ca0f394SUmesh Unnikrishnan return CEED_ERROR_SUCCESS; 486ca0f394SUmesh Unnikrishnan } 496ca0f394SUmesh Unnikrishnan 506ca0f394SUmesh Unnikrishnan //------------------------------------------------------------------------------ 516ca0f394SUmesh Unnikrishnan // Register backend 526ca0f394SUmesh Unnikrishnan //------------------------------------------------------------------------------ 536ca0f394SUmesh Unnikrishnan CEED_INTERN int CeedRegister_Sycl_Gen(void) { return CeedRegister("/gpu/sycl/gen", CeedInit_Sycl_gen, 20); } 546ca0f394SUmesh Unnikrishnan 556ca0f394SUmesh Unnikrishnan //------------------------------------------------------------------------------ 56