xref: /libCEED/rust/libceed-sys/c-src/backends/sycl-gen/ceed-sycl-gen.sycl.cpp (revision dd64fc8452c2d35c954858232143719e6bb2e61d)
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) {
21*dd64fc84SJeremy L Thompson   Ceed       ceed_shared;
22*dd64fc84SJeremy L Thompson   Ceed_Sycl *data, *shared_data;
236ca0f394SUmesh Unnikrishnan   char      *resource_root;
24*dd64fc84SJeremy L Thompson   const char fallback_resource[] = "/gpu/sycl/ref";
25*dd64fc84SJeremy L Thompson 
266ca0f394SUmesh Unnikrishnan   CeedCallBackend(CeedGetResourceRoot(ceed, resource, ":device_id=", &resource_root));
276ca0f394SUmesh Unnikrishnan   if (strcmp(resource_root, "/gpu/sycl") && strcmp(resource_root, "/gpu/sycl/gen")) {
286ca0f394SUmesh Unnikrishnan     // LCOV_EXCL_START
296ca0f394SUmesh Unnikrishnan     return CeedError(ceed, CEED_ERROR_BACKEND, "Sycl backend cannot use resource: %s", resource);
306ca0f394SUmesh Unnikrishnan     // LCOV_EXCL_STOP
316ca0f394SUmesh Unnikrishnan   }
326ca0f394SUmesh Unnikrishnan   CeedCallBackend(CeedFree(&resource_root));
336ca0f394SUmesh Unnikrishnan 
346ca0f394SUmesh Unnikrishnan   CeedCallBackend(CeedCalloc(1, &data));
356ca0f394SUmesh Unnikrishnan   CeedCallBackend(CeedSetData(ceed, data));
366ca0f394SUmesh Unnikrishnan   CeedCallBackend(CeedInit_Sycl(ceed, resource));
376ca0f394SUmesh Unnikrishnan 
386ca0f394SUmesh Unnikrishnan   CeedCallBackend(CeedInit("/gpu/sycl/shared", &ceed_shared));
396ca0f394SUmesh Unnikrishnan 
406ca0f394SUmesh Unnikrishnan   CeedCallBackend(CeedGetData(ceed_shared, &shared_data));
416ca0f394SUmesh Unnikrishnan   // Need to use the same queue everywhere for correct synchronization
426ca0f394SUmesh Unnikrishnan   shared_data->sycl_queue = data->sycl_queue;
436ca0f394SUmesh Unnikrishnan 
446ca0f394SUmesh Unnikrishnan   CeedCallBackend(CeedSetDelegate(ceed, ceed_shared));
456ca0f394SUmesh Unnikrishnan 
46ca735530SJeremy L Thompson   CeedCallBackend(CeedSetOperatorFallbackResource(ceed, fallback_resource));
476ca0f394SUmesh Unnikrishnan 
486ca0f394SUmesh Unnikrishnan   CeedCallBackend(CeedSetBackendFunctionCpp(ceed, "Ceed", ceed, "QFunctionCreate", CeedQFunctionCreate_Sycl_gen));
496ca0f394SUmesh Unnikrishnan   CeedCallBackend(CeedSetBackendFunctionCpp(ceed, "Ceed", ceed, "OperatorCreate", CeedOperatorCreate_Sycl_gen));
506ca0f394SUmesh Unnikrishnan   CeedCallBackend(CeedSetBackendFunctionCpp(ceed, "Ceed", ceed, "Destroy", CeedDestroy_Sycl));
516ca0f394SUmesh Unnikrishnan   return CEED_ERROR_SUCCESS;
526ca0f394SUmesh Unnikrishnan }
536ca0f394SUmesh Unnikrishnan 
546ca0f394SUmesh Unnikrishnan //------------------------------------------------------------------------------
556ca0f394SUmesh Unnikrishnan // Register backend
566ca0f394SUmesh Unnikrishnan //------------------------------------------------------------------------------
576ca0f394SUmesh Unnikrishnan CEED_INTERN int CeedRegister_Sycl_Gen(void) { return CeedRegister("/gpu/sycl/gen", CeedInit_Sycl_gen, 20); }
586ca0f394SUmesh Unnikrishnan 
596ca0f394SUmesh Unnikrishnan //------------------------------------------------------------------------------
60