| 36 | } |
| 37 | |
| 38 | TEST(PD_ZeroCopyRun, zero_copy_run) { |
| 39 | PD_AnalysisConfig *config = PD_NewAnalysisConfig(); |
| 40 | SetConfig(config); |
| 41 | PD_Predictor *predictor = PD_NewPredictor(config); |
| 42 | |
| 43 | int input_num = PD_GetInputNum(predictor); |
| 44 | printf("Input num: %d\n", input_num); |
| 45 | int output_num = PD_GetOutputNum(predictor); |
| 46 | printf("Output num: %d\n", output_num); |
| 47 | |
| 48 | PD_ZeroCopyTensor inputs[2]; |
| 49 | |
| 50 | // inputs[0]: word |
| 51 | PD_InitZeroCopyTensor(&inputs[0]); |
| 52 | inputs[0].name = new char[5]; |
| 53 | snprintf(inputs[0].name, |
| 54 | strlen(PD_GetInputName(predictor, 0)) + 1, |
| 55 | "%s", |
| 56 | PD_GetInputName(predictor, 0)); |
| 57 | |
| 58 | inputs[0].data.capacity = sizeof(int64_t) * 11 * 1; |
| 59 | inputs[0].data.length = inputs[0].data.capacity; |
| 60 | inputs[0].data.data = malloc(inputs[0].data.capacity); |
| 61 | std::vector<int64_t> ref_word( |
| 62 | {12673, 9763, 905, 284, 45, 7474, 20, 17, 1, 4, 9}); |
| 63 | inputs[0].data.data = reinterpret_cast<void *>(ref_word.data()); |
| 64 | |
| 65 | int shape0[] = {11, 1}; |
| 66 | inputs[0].shape.data = reinterpret_cast<void *>(shape0); |
| 67 | inputs[0].shape.capacity = sizeof(shape0); |
| 68 | inputs[0].shape.length = sizeof(shape0); |
| 69 | inputs[0].dtype = PD_INT64; |
| 70 | |
| 71 | size_t lod0[] = {0, 11}; |
| 72 | inputs[0].lod.data = reinterpret_cast<void *>(lod0); |
| 73 | inputs[0].lod.capacity = sizeof(size_t) * 2; |
| 74 | inputs[0].lod.length = sizeof(size_t) * 2; |
| 75 | |
| 76 | PD_SetZeroCopyInput(predictor, &inputs[0]); |
| 77 | |
| 78 | // inputs[1]: mention |
| 79 | PD_InitZeroCopyTensor(&inputs[1]); |
| 80 | inputs[1].name = new char[8]; |
| 81 | snprintf(inputs[1].name, |
| 82 | strlen(PD_GetInputName(predictor, 1)) + 1, |
| 83 | "%s", |
| 84 | PD_GetInputName(predictor, 1)); |
| 85 | |
| 86 | inputs[1].data.capacity = sizeof(int64_t) * 11 * 1; |
| 87 | inputs[1].data.length = inputs[1].data.capacity; |
| 88 | inputs[1].data.data = malloc(inputs[1].data.capacity); |
| 89 | std::vector<int64_t> ref_mention({27, 0, 0, 33, 34, 33, 0, 0, 0, 1, 2}); |
| 90 | inputs[1].data.data = reinterpret_cast<void *>(ref_mention.data()); |
| 91 | |
| 92 | int shape1[] = {11, 1}; |
| 93 | inputs[1].shape.data = reinterpret_cast<void *>(shape1); |
| 94 | inputs[1].shape.capacity = sizeof(shape1); |
| 95 | inputs[1].shape.length = sizeof(shape1); |
nothing calls this directly
no test coverage detected