Skip to content

Commit 2fe032a

Browse files
FrostMLfc500110
andauthored
fix CPU C inference API compile bug (#22702) (#22752)
Co-authored-by: flame <[email protected]>
1 parent 7871612 commit 2fe032a

File tree

6 files changed

+30
-27
lines changed

6 files changed

+30
-27
lines changed

go/paddle/common.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,6 @@ package paddle
2121
import "C"
2222
import "fmt"
2323

24-
type Precision C.Precision
25-
26-
const (
27-
kFloat32 Precision = C.kFloat32
28-
kInt8 Precision = C.kInt8
29-
kHalf Precision = C.kHalf
30-
)
31-
3224
func ConvertCBooleanToGo(b C.bool) bool {
3325
var c_false C.bool
3426
if b != c_false {

go/paddle/config.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ import "C"
2424
import "runtime"
2525
import "unsafe"
2626

27+
type Precision C.Precision
28+
29+
const (
30+
Precision_FLOAT32 Precision = C.kFloat32
31+
Precision_INT8 Precision = C.kInt8
32+
Precision_HALF Precision = C.kHalf
33+
)
34+
2735
type AnalysisConfig struct {
2836
c *C.PD_AnalysisConfig
2937
}

go/paddle/predictor.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,12 @@ func (predictor *Predictor) SetZeroCopyInput(tensor *ZeroCopyTensor) {
102102
func (predictor *Predictor) GetZeroCopyOutput(tensor *ZeroCopyTensor) {
103103
C.PD_GetZeroCopyOutput(predictor.c, tensor.c)
104104
tensor.name = C.GoString(tensor.c.name)
105-
var shape []int32
105+
var shape []int32
106106
shape_hdr := (*reflect.SliceHeader)(unsafe.Pointer(&shape))
107107
shape_hdr.Data = uintptr(unsafe.Pointer(tensor.c.shape.data))
108108
shape_hdr.Len = int(tensor.c.shape.length / C.sizeof_int)
109109
shape_hdr.Cap = int(tensor.c.shape.length / C.sizeof_int)
110-
tensor.Reshape(shape)
110+
tensor.Reshape(shape)
111111
}
112112

113113
func (predictor *Predictor) ZeroCopyRun() {

go/paddle/tensor.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,16 +137,16 @@ func (tensor *ZeroCopyTensor) SetValue(value interface{}) {
137137
tensor.c.data.length = length
138138

139139
switch dtype {
140-
case PaddleDType(UINT8):
140+
case PaddleDType(UINT8):
141141
data := val.Interface().([]uint8)
142142
C.memcpy(tensor.c.data.data, unsafe.Pointer(&data[0]), length)
143-
case PaddleDType(INT32):
143+
case PaddleDType(INT32):
144144
data := val.Interface().([]int32)
145145
C.memcpy(tensor.c.data.data, unsafe.Pointer(&data[0]), length)
146-
case PaddleDType(INT64):
146+
case PaddleDType(INT64):
147147
data := val.Interface().([]int64)
148148
C.memcpy(tensor.c.data.data, unsafe.Pointer(&data[0]), length)
149-
case PaddleDType(FLOAT32):
149+
case PaddleDType(FLOAT32):
150150
data := val.Interface().([]float32)
151151
C.memcpy(tensor.c.data.data, unsafe.Pointer(&data[0]), length)
152152
}

paddle/fluid/inference/CMakeLists.txt

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,20 @@ get_property(fluid_modules GLOBAL PROPERTY FLUID_MODULES)
3939
get_property(cuda_modules GLOBAL PROPERTY CUDA_MODULES)
4040

4141
add_subdirectory(api)
42+
43+
# Create static inference library if needed
44+
# All static libs in inference/api
45+
set(STATIC_INFERENCE_API paddle_inference_api analysis_predictor zero_copy_tensor reset_tensor_array
46+
analysis_config paddle_pass_builder activation_functions ${mkldnn_quantizer_cfg})
47+
create_static_lib(paddle_fluid ${fluid_modules} ${STATIC_INFERENCE_API})
48+
49+
if(NOT APPLE)
50+
# TODO(liuyiqu: Temporarily disable the link flag because it is not support on Mac.
51+
set(LINK_FLAGS "-Wl,--retain-symbols-file ${CMAKE_CURRENT_SOURCE_DIR}/paddle_fluid.sym")
52+
set_target_properties(paddle_fluid PROPERTIES LINK_FLAGS "${LINK_FLAGS}")
53+
endif()
54+
55+
# C inference API
4256
add_subdirectory(capi)
4357

4458
if(WITH_TESTING)
@@ -53,17 +67,6 @@ if(NOT ON_INFER)
5367
return()
5468
endif()
5569

56-
# Create static inference library if needed
57-
# All static libs in inference/api
58-
set(STATIC_INFERENCE_API paddle_inference_api analysis_predictor zero_copy_tensor reset_tensor_array
59-
analysis_config paddle_pass_builder activation_functions ${mkldnn_quantizer_cfg})
60-
create_static_lib(paddle_fluid ${fluid_modules} ${STATIC_INFERENCE_API})
61-
if(NOT APPLE)
62-
# TODO(liuyiqu: Temporarily disable the link flag because it is not support on Mac.
63-
set(LINK_FLAGS "-Wl,--retain-symbols-file ${CMAKE_CURRENT_SOURCE_DIR}/paddle_fluid.sym")
64-
set_target_properties(paddle_fluid PROPERTIES LINK_FLAGS "${LINK_FLAGS}")
65-
endif()
66-
6770
set(SHARED_INFERENCE_SRCS
6871
io.cc
6972
${CMAKE_CURRENT_SOURCE_DIR}/../framework/data_feed.cc

paddle/fluid/inference/capi/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515

1616
set(C_API_SRCS pd_config.cc pd_predictor.cc pd_tensor.cc c_api.cc)
1717

18-
cc_library(paddle_fluid_c SRCS ${C_API_SRCS} DEPS ${fluid_modules} analysis_predictor)
18+
cc_library(paddle_fluid_c SRCS ${C_API_SRCS} DEPS paddle_fluid)
1919

2020
if(NOT ON_INFER)
2121
return()
2222
endif()
2323

2424
# Create inference capi shared library
25-
cc_library(paddle_fluid_c_shared SHARED SRCS ${C_API_SRCS} DEPS ${fluid_modules} analysis_predictor)
25+
cc_library(paddle_fluid_c_shared SHARED SRCS ${C_API_SRCS} DEPS paddle_fluid)
2626
set_target_properties(paddle_fluid_c_shared PROPERTIES OUTPUT_NAME paddle_fluid_c)
2727
if(WIN32)
2828
target_link_libraries(paddle_fluid_c_shared shlwapi.lib)

0 commit comments

Comments
 (0)