#include <ceed.h>
#include <ceed/backend.h>
#include <cuda_runtime.h>
#include "../cuda/ceed-cuda-common.h"
#include "ceed-cuda-gen.h"
static int CeedQFunctionApply_Cuda_gen(CeedQFunction qf, CeedInt Q, CeedVector *U, CeedVector *V) {
Ceed ceed;
CeedCallBackend(CeedQFunctionGetCeed(qf, &ceed));
return CeedError(ceed, CEED_ERROR_BACKEND, "Backend does not implement QFunctionApply");
}
static int CeedQFunctionDestroy_Cuda_gen(CeedQFunction qf) {
Ceed ceed;
CeedQFunction_Cuda_gen *data;
CeedCallBackend(CeedQFunctionGetData(qf, &data));
CeedCallBackend(CeedQFunctionGetCeed(qf, &ceed));
CeedCallCuda(ceed, cudaFree(data->d_c));
CeedCallBackend(CeedFree(&data->q_function_source));
CeedCallBackend(CeedFree(&data));
return CEED_ERROR_SUCCESS;
}
int CeedQFunctionCreate_Cuda_gen(CeedQFunction qf) {
Ceed ceed;
CeedQFunction_Cuda_gen *data;
CeedQFunctionGetCeed(qf, &ceed);
CeedCallBackend(CeedCalloc(1, &data));
CeedCallBackend(CeedQFunctionSetData(qf, data));
CeedCallBackend(CeedQFunctionGetKernelName(qf, &data->q_function_name));
CeedDebug256(ceed, CEED_DEBUG_COLOR_SUCCESS, "----- Loading QFunction User Source -----\n");
CeedCallBackend(CeedQFunctionLoadSourceToBuffer(qf, &data->q_function_source));
CeedDebug256(ceed, CEED_DEBUG_COLOR_SUCCESS, "----- Loading QFunction User Source Complete! -----\n");
CeedCheck(data->q_function_source, ceed, CEED_ERROR_UNSUPPORTED, "/gpu/cuda/gen backend requires QFunction source code file");
CeedCallBackend(CeedSetBackendFunction(ceed, "QFunction", qf, "Apply", CeedQFunctionApply_Cuda_gen));
CeedCallBackend(CeedSetBackendFunction(ceed, "QFunction", qf, "Destroy", CeedQFunctionDestroy_Cuda_gen));
return CEED_ERROR_SUCCESS;
}