diff --git a/go/paddle/common.go b/go/paddle/common.go index 346dc3f395bfe6ba4ae9fdc716f41a58b2bb4725..b29efbdf3022b644d42b22cc5f005f12e0775ab9 100644 --- a/go/paddle/common.go +++ b/go/paddle/common.go @@ -21,14 +21,6 @@ package paddle import "C" import "fmt" -type Precision C.Precision - -const ( - kFloat32 Precision = C.kFloat32 - kInt8 Precision = C.kInt8 - kHalf Precision = C.kHalf -) - func ConvertCBooleanToGo(b C.bool) bool { var c_false C.bool if b != c_false { diff --git a/go/paddle/config.go b/go/paddle/config.go index 5480365d58069b44b24fbb027e62e7809e4eb5cf..05e126114b17082d4d806f2cc6786154d7125805 100644 --- a/go/paddle/config.go +++ b/go/paddle/config.go @@ -24,6 +24,14 @@ import "C" import "runtime" import "unsafe" +type Precision C.Precision + +const ( + Precision_FLOAT32 Precision = C.kFloat32 + Precision_INT8 Precision = C.kInt8 + Precision_HALF Precision = C.kHalf +) + type AnalysisConfig struct { c *C.PD_AnalysisConfig } diff --git a/go/paddle/predictor.go b/go/paddle/predictor.go index 8d034e0d6ee2147ed802ed8ef1eb3aeaf8408352..2bae7854c31e577d14609fa57bfaaad445a08737 100644 --- a/go/paddle/predictor.go +++ b/go/paddle/predictor.go @@ -102,12 +102,12 @@ func (predictor *Predictor) SetZeroCopyInput(tensor *ZeroCopyTensor) { func (predictor *Predictor) GetZeroCopyOutput(tensor *ZeroCopyTensor) { C.PD_GetZeroCopyOutput(predictor.c, tensor.c) tensor.name = C.GoString(tensor.c.name) - var shape []int32 + var shape []int32 shape_hdr := (*reflect.SliceHeader)(unsafe.Pointer(&shape)) shape_hdr.Data = uintptr(unsafe.Pointer(tensor.c.shape.data)) shape_hdr.Len = int(tensor.c.shape.length / C.sizeof_int) shape_hdr.Cap = int(tensor.c.shape.length / C.sizeof_int) - tensor.Reshape(shape) + tensor.Reshape(shape) } func (predictor *Predictor) ZeroCopyRun() { diff --git a/go/paddle/tensor.go b/go/paddle/tensor.go index 3a77d92bee8796e4c41cdf4d21a87304f446fcd6..4da99ea840f64e82bf493e8dbb558121b65b6657 100644 --- a/go/paddle/tensor.go +++ b/go/paddle/tensor.go @@ -137,16 +137,16 @@ func (tensor *ZeroCopyTensor) SetValue(value interface{}) { tensor.c.data.length = length switch dtype { - case PaddleDType(UINT8): + case PaddleDType(UINT8): data := val.Interface().([]uint8) C.memcpy(tensor.c.data.data, unsafe.Pointer(&data[0]), length) - case PaddleDType(INT32): + case PaddleDType(INT32): data := val.Interface().([]int32) C.memcpy(tensor.c.data.data, unsafe.Pointer(&data[0]), length) - case PaddleDType(INT64): + case PaddleDType(INT64): data := val.Interface().([]int64) C.memcpy(tensor.c.data.data, unsafe.Pointer(&data[0]), length) - case PaddleDType(FLOAT32): + case PaddleDType(FLOAT32): data := val.Interface().([]float32) C.memcpy(tensor.c.data.data, unsafe.Pointer(&data[0]), length) } diff --git a/paddle/fluid/inference/CMakeLists.txt b/paddle/fluid/inference/CMakeLists.txt index 1f7adb414d8a42420e09cb7b667abe96d22a9c95..904b77281364e78ade58d879bc49ee9cd5a0f598 100644 --- a/paddle/fluid/inference/CMakeLists.txt +++ b/paddle/fluid/inference/CMakeLists.txt @@ -39,6 +39,20 @@ get_property(fluid_modules GLOBAL PROPERTY FLUID_MODULES) get_property(cuda_modules GLOBAL PROPERTY CUDA_MODULES) add_subdirectory(api) + +# Create static inference library if needed +# All static libs in inference/api +set(STATIC_INFERENCE_API paddle_inference_api analysis_predictor zero_copy_tensor reset_tensor_array + analysis_config paddle_pass_builder activation_functions ${mkldnn_quantizer_cfg}) +create_static_lib(paddle_fluid ${fluid_modules} ${STATIC_INFERENCE_API}) + +if(NOT APPLE) + # TODO(liuyiqu: Temporarily disable the link flag because it is not support on Mac. + set(LINK_FLAGS "-Wl,--retain-symbols-file ${CMAKE_CURRENT_SOURCE_DIR}/paddle_fluid.sym") + set_target_properties(paddle_fluid PROPERTIES LINK_FLAGS "${LINK_FLAGS}") +endif() + +# C inference API add_subdirectory(capi) if(WITH_TESTING) @@ -53,17 +67,6 @@ if(NOT ON_INFER) return() endif() -# Create static inference library if needed -# All static libs in inference/api -set(STATIC_INFERENCE_API paddle_inference_api analysis_predictor zero_copy_tensor reset_tensor_array - analysis_config paddle_pass_builder activation_functions ${mkldnn_quantizer_cfg}) -create_static_lib(paddle_fluid ${fluid_modules} ${STATIC_INFERENCE_API}) -if(NOT APPLE) - # TODO(liuyiqu: Temporarily disable the link flag because it is not support on Mac. - set(LINK_FLAGS "-Wl,--retain-symbols-file ${CMAKE_CURRENT_SOURCE_DIR}/paddle_fluid.sym") - set_target_properties(paddle_fluid PROPERTIES LINK_FLAGS "${LINK_FLAGS}") -endif() - set(SHARED_INFERENCE_SRCS io.cc ${CMAKE_CURRENT_SOURCE_DIR}/../framework/data_feed.cc diff --git a/paddle/fluid/inference/capi/CMakeLists.txt b/paddle/fluid/inference/capi/CMakeLists.txt index 92be4b850fa277a46bba50eb4aa705b0c033cfa7..7a555279f85089331d3e66f11f62574c4ae8b697 100644 --- a/paddle/fluid/inference/capi/CMakeLists.txt +++ b/paddle/fluid/inference/capi/CMakeLists.txt @@ -15,14 +15,14 @@ set(C_API_SRCS pd_config.cc pd_predictor.cc pd_tensor.cc c_api.cc) -cc_library(paddle_fluid_c SRCS ${C_API_SRCS} DEPS ${fluid_modules} analysis_predictor) +cc_library(paddle_fluid_c SRCS ${C_API_SRCS} DEPS paddle_fluid) if(NOT ON_INFER) return() endif() # Create inference capi shared library -cc_library(paddle_fluid_c_shared SHARED SRCS ${C_API_SRCS} DEPS ${fluid_modules} analysis_predictor) +cc_library(paddle_fluid_c_shared SHARED SRCS ${C_API_SRCS} DEPS paddle_fluid) set_target_properties(paddle_fluid_c_shared PROPERTIES OUTPUT_NAME paddle_fluid_c) if(WIN32) target_link_libraries(paddle_fluid_c_shared shlwapi.lib)