1 // Copyright (c) 2017-2024, Lawrence Livermore National Security, LLC and other CEED contributors. 2 // All Rights Reserved. See the top-level LICENSE and NOTICE files for details. 3 // 4 // SPDX-License-Identifier: BSD-2-Clause 5 // 6 // This file is part of CEED: http://github.com/ceed 7 8 #include <ceed/backend.h> 9 #include <ceed/ceed.h> 10 #include <sycl/sycl.hpp> 11 #include <stdio.h> 12 #include <string.h> 13 14 #include "ceed-sycl-gen.hpp" 15 16 //------------------------------------------------------------------------------ 17 // Apply QFunction 18 //------------------------------------------------------------------------------ 19 static int CeedQFunctionApply_Sycl_gen(CeedQFunction qf, CeedInt Q, CeedVector *U, CeedVector *V) { 20 return CeedError(CeedQFunctionReturnCeed(qf), CEED_ERROR_BACKEND, "Backend does not implement QFunctionApply"); 21 } 22 23 //------------------------------------------------------------------------------ 24 // Destroy QFunction 25 //------------------------------------------------------------------------------ 26 static int CeedQFunctionDestroy_Sycl_gen(CeedQFunction qf) { 27 Ceed ceed; 28 Ceed_Sycl *data; 29 CeedQFunction_Sycl_gen *impl; 30 31 CeedCallBackend(CeedQFunctionGetCeed(qf, &ceed)); 32 CeedCallBackend(CeedQFunctionGetData(qf, &impl)); 33 CeedCallBackend(CeedGetData(ceed, &data)); 34 35 // Wait for all work to finish before freeing memory 36 CeedCallSycl(ceed, data->sycl_queue.wait_and_throw()); 37 CeedCallSycl(ceed, sycl::free(impl->d_c, data->sycl_context)); 38 39 CeedCallBackend(CeedFree(&impl->qfunction_source)); 40 CeedCallBackend(CeedFree(&impl)); 41 return CEED_ERROR_SUCCESS; 42 } 43 44 //------------------------------------------------------------------------------ 45 // Create QFunction 46 //------------------------------------------------------------------------------ 47 int CeedQFunctionCreate_Sycl_gen(CeedQFunction qf) { 48 Ceed ceed; 49 CeedQFunction_Sycl_gen *impl; 50 51 CeedCallBackend(CeedQFunctionGetCeed(qf, &ceed)); 52 CeedCallBackend(CeedCalloc(1, &impl)); 53 CeedCallBackend(CeedQFunctionSetData(qf, impl)); 54 55 // Read QFunction source 56 CeedCallBackend(CeedQFunctionGetKernelName(qf, &impl->qfunction_name)); 57 CeedDebug256(ceed, 2, "----- Loading QFunction User Source -----\n"); 58 CeedCallBackend(CeedQFunctionLoadSourceToBuffer(qf, &impl->qfunction_source)); 59 CeedDebug256(ceed, 2, "----- Loading QFunction User Source Complete! -----\n"); 60 CeedCheck(impl->qfunction_source, ceed, CEED_ERROR_UNSUPPORTED, "/gpu/sycl/gen backend requires QFunction source code file"); 61 62 CeedCallBackend(CeedSetBackendFunctionCpp(ceed, "QFunction", qf, "Apply", CeedQFunctionApply_Sycl_gen)); 63 CeedCallBackend(CeedSetBackendFunctionCpp(ceed, "QFunction", qf, "Destroy", CeedQFunctionDestroy_Sycl_gen)); 64 return CEED_ERROR_SUCCESS; 65 } 66 67 //------------------------------------------------------------------------------ 68