16ca0f394SUmesh Unnikrishnan // Copyright (c) 2017-2022, 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; 22dd64fc84SJeremy L Thompson Ceed_Sycl *data, *shared_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)); 27*4e3038a5SJeremy L Thompson CeedChk(!strcmp(resource_root, "/gpu/sycl") || !strcmp(resource_root, "/gpu/sycl/gen"), ceed, CEED_ERROR_BACKEND, 28*4e3038a5SJeremy 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 376ca0f394SUmesh Unnikrishnan CeedCallBackend(CeedGetData(ceed_shared, &shared_data)); 386ca0f394SUmesh Unnikrishnan // Need to use the same queue everywhere for correct synchronization 396ca0f394SUmesh Unnikrishnan shared_data->sycl_queue = data->sycl_queue; 406ca0f394SUmesh Unnikrishnan 416ca0f394SUmesh Unnikrishnan CeedCallBackend(CeedSetDelegate(ceed, ceed_shared)); 426ca0f394SUmesh Unnikrishnan 43ca735530SJeremy L Thompson CeedCallBackend(CeedSetOperatorFallbackResource(ceed, fallback_resource)); 446ca0f394SUmesh 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