1 // Copyright (c) 2017-2022, 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 Ceed ceed; 21 CeedCallBackend(CeedQFunctionGetCeed(qf, &ceed)); 22 return CeedError(ceed, CEED_ERROR_BACKEND, "Backend does not implement QFunctionApply"); 23 } 24 25 //------------------------------------------------------------------------------ 26 // Destroy QFunction 27 //------------------------------------------------------------------------------ 28 static int CeedQFunctionDestroy_Sycl_gen(CeedQFunction qf) { 29 Ceed ceed; 30 CeedCallBackend(CeedQFunctionGetCeed(qf, &ceed)); 31 CeedQFunction_Sycl_gen *impl; 32 CeedCallBackend(CeedQFunctionGetData(qf, &impl)); 33 Ceed_Sycl *data; 34 CeedCallBackend(CeedGetData(ceed, &data)); 35 36 // Wait for all work to finish before freeing memory 37 CeedCallSycl(ceed, data->sycl_queue.wait_and_throw()); 38 CeedCallSycl(ceed, sycl::free(impl->d_c, data->sycl_context)); 39 40 CeedCallBackend(CeedFree(&impl->q_function_source)); 41 CeedCallBackend(CeedFree(&impl)); 42 return CEED_ERROR_SUCCESS; 43 } 44 45 //------------------------------------------------------------------------------ 46 // Create QFunction 47 //------------------------------------------------------------------------------ 48 int CeedQFunctionCreate_Sycl_gen(CeedQFunction qf) { 49 Ceed ceed; 50 CeedQFunctionGetCeed(qf, &ceed); 51 CeedQFunction_Sycl_gen *impl; 52 CeedCallBackend(CeedCalloc(1, &impl)); 53 CeedCallBackend(CeedQFunctionSetData(qf, impl)); 54 55 // Read QFunction source 56 CeedCallBackend(CeedQFunctionGetKernelName(qf, &impl->q_function_name)); 57 CeedDebug256(ceed, 2, "----- Loading QFunction User Source -----\n"); 58 CeedCallBackend(CeedQFunctionLoadSourceToBuffer(qf, &impl->q_function_source)); 59 CeedDebug256(ceed, 2, "----- Loading QFunction User Source Complete! -----\n"); 60 if (!impl->q_function_source) { 61 // LCOV_EXCL_START 62 return CeedError(ceed, CEED_ERROR_UNSUPPORTED, "/gpu/sycl/gen backend requires QFunction source code file"); 63 // LCOV_EXCL_STOP 64 } 65 66 CeedCallBackend(CeedSetBackendFunctionCpp(ceed, "QFunction", qf, "Apply", CeedQFunctionApply_Sycl_gen)); 67 CeedCallBackend(CeedSetBackendFunctionCpp(ceed, "QFunction", qf, "Destroy", CeedQFunctionDestroy_Sycl_gen)); 68 return CEED_ERROR_SUCCESS; 69 } 70 71 //------------------------------------------------------------------------------ 72