| ceed-qfunction.c (cb03979f09f11f2f58ca1dff8031348aa48729d3) | ceed-qfunction.c (ca5eadf8df4f5a5d6322e2e571e4886ce218945b) |
|---|---|
| 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/ceed.h> --- 204 unchanged lines hidden (view full) --- 213 @param qf CeedQFunction 214 @param[out] kernel_name Variable to store source path string 215 216 @return An error code: 0 - success, otherwise - failure 217 218 @ref Backend 219**/ 220int CeedQFunctionGetKernelName(CeedQFunction qf, char **kernel_name) { | 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/ceed.h> --- 204 unchanged lines hidden (view full) --- 213 @param qf CeedQFunction 214 @param[out] kernel_name Variable to store source path string 215 216 @return An error code: 0 - success, otherwise - failure 217 218 @ref Backend 219**/ 220int CeedQFunctionGetKernelName(CeedQFunction qf, char **kernel_name) { |
| 221 int ierr; 222 223 if (!qf->kernel_name ) { 224 Ceed ceed; 225 char *kernel_name_copy; 226 ierr = CeedQFunctionGetCeed(qf, &ceed); CeedChk(ierr); 227 228 if (qf->user_source) { 229 const char *kernel_name = strrchr(qf->user_source, ':') + 1; 230 size_t kernel_name_len = strlen(kernel_name); 231 232 ierr = CeedCalloc(kernel_name_len + 1, &kernel_name_copy); CeedChk(ierr); 233 memcpy(kernel_name_copy, kernel_name, kernel_name_len); 234 } else { 235 ierr = CeedCalloc(1, &kernel_name_copy); CeedChk(ierr); 236 } 237 qf->kernel_name = kernel_name_copy; 238 } 239 |
|
| 221 *kernel_name = (char *) qf->kernel_name; 222 return CEED_ERROR_SUCCESS; 223} 224 225/** 226 @brief Get the source path string for a CeedQFunction 227 228 @param qf CeedQFunction 229 @param[out] source_path Variable to store source path string 230 231 @return An error code: 0 - success, otherwise - failure 232 233 @ref Backend 234**/ 235int CeedQFunctionGetSourcePath(CeedQFunction qf, char **source_path) { | 240 *kernel_name = (char *) qf->kernel_name; 241 return CEED_ERROR_SUCCESS; 242} 243 244/** 245 @brief Get the source path string for a CeedQFunction 246 247 @param qf CeedQFunction 248 @param[out] source_path Variable to store source path string 249 250 @return An error code: 0 - success, otherwise - failure 251 252 @ref Backend 253**/ 254int CeedQFunctionGetSourcePath(CeedQFunction qf, char **source_path) { |
| 255 int ierr; 256 257 if (!qf->source_path && qf->user_source) { 258 Ceed ceed; 259 bool is_absolute_path; 260 char *absolute_path, *source_path_copy; 261 const char *kernel_name = strrchr(qf->user_source, ':') + 1; 262 size_t kernel_name_len = strlen(kernel_name); 263 264 ierr = CeedQFunctionGetCeed(qf, &ceed); CeedChk(ierr); 265 266 ierr = CeedCheckFilePath(ceed, qf->user_source, &is_absolute_path); 267 CeedChk(ierr); 268 if (is_absolute_path) { 269 absolute_path = (char *)qf->user_source; 270 } else { 271 ierr = CeedGetJitAbsolutePath(ceed, qf->user_source, &absolute_path); 272 CeedChk(ierr); 273 } 274 275 size_t source_len = strlen(absolute_path) - kernel_name_len - 1; 276 ierr = CeedCalloc(source_len + 1, &source_path_copy); CeedChk(ierr); 277 memcpy(source_path_copy, absolute_path, source_len); 278 qf->source_path = source_path_copy; 279 280 if (!is_absolute_path) { 281 ierr = CeedFree(&absolute_path); CeedChk(ierr); 282 } 283 } 284 |
|
| 236 *source_path = (char *) qf->source_path; 237 return CEED_ERROR_SUCCESS; 238} 239 240/** 241 @brief Initalize and load QFunction source file into string buffer, including 242 full text of local files in place of `#include "local.h"`. 243 The `buffer` is set to `NULL` if there is no QFunction source file. --- 319 unchanged lines hidden (view full) --- 563 arguments. 564 565 @ref User 566**/ 567int CeedQFunctionCreateInterior(Ceed ceed, CeedInt vec_length, 568 CeedQFunctionUser f, 569 const char *source, CeedQFunction *qf) { 570 int ierr; | 285 *source_path = (char *) qf->source_path; 286 return CEED_ERROR_SUCCESS; 287} 288 289/** 290 @brief Initalize and load QFunction source file into string buffer, including 291 full text of local files in place of `#include "local.h"`. 292 The `buffer` is set to `NULL` if there is no QFunction source file. --- 319 unchanged lines hidden (view full) --- 612 arguments. 613 614 @ref User 615**/ 616int CeedQFunctionCreateInterior(Ceed ceed, CeedInt vec_length, 617 CeedQFunctionUser f, 618 const char *source, CeedQFunction *qf) { 619 int ierr; |
| 571 char *source_copy, *kernel_name_copy; | 620 char *user_source_copy; |
| 572 573 if (!ceed->QFunctionCreate) { 574 Ceed delegate; 575 ierr = CeedGetObjectDelegate(ceed, &delegate, "QFunction"); CeedChk(ierr); 576 577 if (!delegate) 578 // LCOV_EXCL_START 579 return CeedError(ceed, CEED_ERROR_UNSUPPORTED, --- 18 unchanged lines hidden (view full) --- 598 ierr = CeedReference(ceed); CeedChk(ierr); 599 (*qf)->ref_count = 1; 600 (*qf)->vec_length = vec_length; 601 (*qf)->is_identity = false; 602 (*qf)->is_context_writable = true; 603 (*qf)->function = f; 604 (*qf)->user_flop_estimate = -1; 605 if (strlen(source)) { | 621 622 if (!ceed->QFunctionCreate) { 623 Ceed delegate; 624 ierr = CeedGetObjectDelegate(ceed, &delegate, "QFunction"); CeedChk(ierr); 625 626 if (!delegate) 627 // LCOV_EXCL_START 628 return CeedError(ceed, CEED_ERROR_UNSUPPORTED, --- 18 unchanged lines hidden (view full) --- 647 ierr = CeedReference(ceed); CeedChk(ierr); 648 (*qf)->ref_count = 1; 649 (*qf)->vec_length = vec_length; 650 (*qf)->is_identity = false; 651 (*qf)->is_context_writable = true; 652 (*qf)->function = f; 653 (*qf)->user_flop_estimate = -1; 654 if (strlen(source)) { |
| 606 bool is_absolute_path; 607 char *absolute_path; | 655 size_t user_source_len = strlen(source); |
| 608 | 656 |
| 609 ierr = CeedCheckFilePath(ceed, source, &is_absolute_path); CeedChk(ierr); 610 if (is_absolute_path) { 611 absolute_path = (char *)source; 612 } else { 613 ierr = CeedGetJitAbsolutePath(ceed, source, &absolute_path); CeedChk(ierr); 614 } 615 616 const char *kernel_name = strrchr(absolute_path, ':') + 1; 617 size_t kernel_name_len = strlen(kernel_name); 618 ierr = CeedCalloc(kernel_name_len + 1, &kernel_name_copy); CeedChk(ierr); 619 memcpy(kernel_name_copy, kernel_name, kernel_name_len); 620 (*qf)->kernel_name = kernel_name_copy; 621 622 size_t source_len = strlen(absolute_path) - kernel_name_len - 1; 623 ierr = CeedCalloc(source_len + 1, &source_copy); CeedChk(ierr); 624 memcpy(source_copy, absolute_path, source_len); 625 (*qf)->source_path = source_copy; 626 627 if (!is_absolute_path) { 628 ierr = CeedFree(&absolute_path); CeedChk(ierr); 629 } | 657 ierr = CeedCalloc(user_source_len + 1, &user_source_copy); CeedChk(ierr); 658 memcpy(user_source_copy, source, user_source_len); 659 (*qf)->user_source = user_source_copy; |
| 630 } 631 ierr = CeedCalloc(CEED_FIELD_MAX, &(*qf)->input_fields); CeedChk(ierr); 632 ierr = CeedCalloc(CEED_FIELD_MAX, &(*qf)->output_fields); CeedChk(ierr); 633 ierr = ceed->QFunctionCreate(*qf); CeedChk(ierr); 634 return CEED_ERROR_SUCCESS; 635} 636 637/** --- 326 unchanged lines hidden (view full) --- 964 @param[in] stream Stream to write; typically stdout/stderr or a file 965 966 @return Error code: 0 - success, otherwise - failure 967 968 @ref User 969**/ 970int CeedQFunctionView(CeedQFunction qf, FILE *stream) { 971 int ierr; | 660 } 661 ierr = CeedCalloc(CEED_FIELD_MAX, &(*qf)->input_fields); CeedChk(ierr); 662 ierr = CeedCalloc(CEED_FIELD_MAX, &(*qf)->output_fields); CeedChk(ierr); 663 ierr = ceed->QFunctionCreate(*qf); CeedChk(ierr); 664 return CEED_ERROR_SUCCESS; 665} 666 667/** --- 326 unchanged lines hidden (view full) --- 994 @param[in] stream Stream to write; typically stdout/stderr or a file 995 996 @return Error code: 0 - success, otherwise - failure 997 998 @ref User 999**/ 1000int CeedQFunctionView(CeedQFunction qf, FILE *stream) { 1001 int ierr; |
| 1002 char *kernel_name; |
|
| 972 | 1003 |
| 1004 ierr = CeedQFunctionGetKernelName(qf, &kernel_name); CeedChk(ierr); |
|
| 973 fprintf(stream, "%sCeedQFunction - %s\n", 974 qf->is_gallery ? "Gallery " : "User ", | 1005 fprintf(stream, "%sCeedQFunction - %s\n", 1006 qf->is_gallery ? "Gallery " : "User ", |
| 975 qf->is_gallery ? qf->gallery_name : qf->kernel_name); | 1007 qf->is_gallery ? qf->gallery_name : kernel_name); |
| 976 977 fprintf(stream, " %" CeedInt_FMT " input field%s:\n", qf->num_input_fields, 978 qf->num_input_fields>1 ? "s" : ""); 979 for (CeedInt i=0; i<qf->num_input_fields; i++) { 980 ierr = CeedQFunctionFieldView(qf->input_fields[i], i, 1, stream); 981 CeedChk(ierr); 982 } 983 --- 82 unchanged lines hidden (view full) --- 1066 ierr = CeedFree(&(*qf)->output_fields[i]); CeedChk(ierr); 1067 } 1068 ierr = CeedFree(&(*qf)->input_fields); CeedChk(ierr); 1069 ierr = CeedFree(&(*qf)->output_fields); CeedChk(ierr); 1070 1071 // User context data object 1072 ierr = CeedQFunctionContextDestroy(&(*qf)->ctx); CeedChk(ierr); 1073 | 1008 1009 fprintf(stream, " %" CeedInt_FMT " input field%s:\n", qf->num_input_fields, 1010 qf->num_input_fields>1 ? "s" : ""); 1011 for (CeedInt i=0; i<qf->num_input_fields; i++) { 1012 ierr = CeedQFunctionFieldView(qf->input_fields[i], i, 1, stream); 1013 CeedChk(ierr); 1014 } 1015 --- 82 unchanged lines hidden (view full) --- 1098 ierr = CeedFree(&(*qf)->output_fields[i]); CeedChk(ierr); 1099 } 1100 ierr = CeedFree(&(*qf)->input_fields); CeedChk(ierr); 1101 ierr = CeedFree(&(*qf)->output_fields); CeedChk(ierr); 1102 1103 // User context data object 1104 ierr = CeedQFunctionContextDestroy(&(*qf)->ctx); CeedChk(ierr); 1105 |
| 1106 ierr = CeedFree(&(*qf)->user_source); CeedChk(ierr); |
|
| 1074 ierr = CeedFree(&(*qf)->source_path); CeedChk(ierr); 1075 ierr = CeedFree(&(*qf)->gallery_name); CeedChk(ierr); 1076 ierr = CeedFree(&(*qf)->kernel_name); CeedChk(ierr); 1077 ierr = CeedDestroy(&(*qf)->ceed); CeedChk(ierr); 1078 ierr = CeedFree(qf); CeedChk(ierr); 1079 return CEED_ERROR_SUCCESS; 1080} 1081 1082/// @} | 1107 ierr = CeedFree(&(*qf)->source_path); CeedChk(ierr); 1108 ierr = CeedFree(&(*qf)->gallery_name); CeedChk(ierr); 1109 ierr = CeedFree(&(*qf)->kernel_name); CeedChk(ierr); 1110 ierr = CeedDestroy(&(*qf)->ceed); CeedChk(ierr); 1111 ierr = CeedFree(qf); CeedChk(ierr); 1112 return CEED_ERROR_SUCCESS; 1113} 1114 1115/// @} |