@@ -382,6 +382,9 @@ function(cc_binary TARGET_NAME)
382
382
endif ()
383
383
get_property (os_dependency_modules GLOBAL PROPERTY OS_DEPENDENCY_MODULES)
384
384
target_link_libraries (${TARGET_NAME} ${os_dependency_modules} )
385
+ if (WITH_ROCM)
386
+ target_link_libraries (${TARGET_NAME} ${ROCM_HIPRTC_LIB} )
387
+ endif ()
385
388
386
389
check_coverage_opt(${TARGET_NAME} ${cc_binary_SRCS} )
387
390
@@ -403,6 +406,9 @@ function(cc_test_build TARGET_NAME)
403
406
target_link_libraries (${TARGET_NAME} ${cc_test_DEPS} ${os_dependency_modules} paddle_gtest_main lod_tensor memory gtest gflags glog)
404
407
add_dependencies (${TARGET_NAME} ${cc_test_DEPS} paddle_gtest_main lod_tensor memory gtest gflags glog)
405
408
common_link(${TARGET_NAME} )
409
+ if (WITH_ROCM)
410
+ target_link_libraries (${TARGET_NAME} ${ROCM_HIPRTC_LIB} )
411
+ endif ()
406
412
endif ()
407
413
408
414
check_coverage_opt(${TARGET_NAME} ${cc_test_SRCS} )
@@ -538,33 +544,24 @@ function(nv_test TARGET_NAME)
538
544
endfunction (nv_test)
539
545
540
546
function (hip_library TARGET_NAME)
541
- if (WITH_ROCM_PLATFORM )
547
+ if (WITH_ROCM )
542
548
set (options STATIC static SHARED shared)
543
549
set (oneValueArgs "" )
544
550
set (multiValueArgs SRCS DEPS)
545
551
cmake_parse_arguments (hip_library "${options} " "${oneValueArgs} " "${multiValueArgs} " ${ARGN} )
546
- set (_sources ${hip_library_SRCS} )
547
- set_source_files_properties (${_sources} PROPERTIES HIP_SOURCE_PROPERTY_FORMAT 1)
548
- HIP_PREPARE_TARGET_COMMANDS(${TARGET_NAME} OBJ _generated_files _source_files ${_sources} HIPCC_OPTIONS ${_hipcc_options} HCC_OPTIONS ${_hcc_options} NVCC_OPTIONS ${_nvcc_options} )
549
- if (_source_files)
550
- list (REMOVE_ITEM _sources ${_source_files} )
551
- endif ()
552
552
if (hip_library_SRCS)
553
+ # FindHIP.cmake defined hip_add_library, HIP_SOURCE_PROPERTY_FORMAT is requried if no .cu files found
554
+ if (NOT ${CMAKE_CURRENT_SOURCE_DIR} MATCHES ".*/operators" )
555
+ set_source_files_properties (${hip_library_SRCS} PROPERTIES HIP_SOURCE_PROPERTY_FORMAT 1)
556
+ endif ()
553
557
if (hip_library_SHARED OR hip_library_shared) # build *.so
554
- add_library (${TARGET_NAME} SHARED ${_cmake_options} ${_generated_files} ${_sources} )
555
- set_target_properties (${TARGET_NAME} PROPERTIES LINKER_LANGUAGE HIP)
558
+ hip_add_library(${TARGET_NAME} SHARED ${hip_library_SRCS} )
556
559
else ()
557
- add_library (${TARGET_NAME} STATIC ${_cmake_options} ${_generated_files} ${_sources} )
558
- set_target_properties (${TARGET_NAME} PROPERTIES LINKER_LANGUAGE CXX)
559
- target_link_libraries (${TARGET_NAME} ${ROCM_PATH} /hip/lib/libhip_hcc.so)
560
+ hip_add_library(${TARGET_NAME} STATIC ${hip_library_SRCS} )
560
561
find_fluid_modules(${TARGET_NAME} )
561
562
endif ()
562
- if ("${hip_library_DEPS} " MATCHES "ARCHIVE_START" )
563
- # Support linking flags: --whole-archive (Linux) / -force_load (MacOS).
564
- # WARNING: Please don't use ARCHIVE_START&ARCHIVE_END if TARGET_NAME will be linked by other libraries.
565
- target_circle_link_libraries(${TARGET_NAME} ${hip_library_DEPS} )
566
- list (REMOVE_ITEM hip_library_DEPS ARCHIVE_START ARCHIVE_END)
567
- else ()
563
+ if (hip_library_DEPS)
564
+ add_dependencies (${TARGET_NAME} ${hip_library_DEPS} )
568
565
target_link_libraries (${TARGET_NAME} ${hip_library_DEPS} )
569
566
endif ()
570
567
# cpplint code style
@@ -574,107 +571,57 @@ function(hip_library TARGET_NAME)
574
571
list (APPEND hip_library_HEADERS ${CMAKE_CURRENT_SOURCE_DIR} /${source} .h)
575
572
endif ()
576
573
endforeach ()
577
-
578
- check_coverage_opt(${TARGET_NAME} ${hip_library_SRCS} )
579
-
580
574
else (hip_library_SRCS)
581
575
if (hip_library_DEPS)
582
- merge_static_libs(${TARGET_NAME} ${hip_library_DEPS} )
576
+ list (REMOVE_DUPLICATES hip_library_DEPS)
577
+ generate_dummy_static_lib(LIB_NAME ${TARGET_NAME} FILE_PATH ${target_SRCS} GENERATOR "generic.cmake:hip_library" )
578
+
579
+ target_link_libraries (${TARGET_NAME} ${hip_library_DEPS} )
580
+ add_dependencies (${TARGET_NAME} ${hip_library_DEPS} )
583
581
else ()
584
- message (FATAL "Please specify source file or library in nv_library ." )
582
+ message (FATAL "Please specify source file or library in hip_library ." )
585
583
endif ()
586
584
endif (hip_library_SRCS)
587
585
endif ()
588
586
endfunction (hip_library)
589
587
590
- function (hip_library_ops TARGET_NAME)
591
- if (WITH_ROCM_PLATFORM)
592
- set (options STATIC static SHARED shared)
593
- set (oneValueArgs "" )
594
- set (multiValueArgs SRCS DEPS)
595
- cmake_parse_arguments (hip_library_ops "${options} " "${oneValueArgs} " "${multiValueArgs} " ${ARGN} )
596
- set (_sources ${hip_library_ops_SRCS} )
597
- HIP_PREPARE_TARGET_COMMANDS(${TARGET_NAME} OBJ _generated_files _source_files ${_sources} HIPCC_OPTIONS ${_hipcc_options} HCC_OPTIONS ${_hcc_options} NVCC_OPTIONS ${_nvcc_options} )
598
- if (_source_files)
599
- list (REMOVE_ITEM _sources ${_source_files} )
600
- endif ()
601
- if (hip_library_ops_SRCS)
602
- if (hip_library_ops_SHARED OR hip_library_ops_shared) # build *.so
603
- add_library (${TARGET_NAME} SHARED ${_cmake_options} ${_generated_files} ${_sources} )
604
- set_target_properties (${TARGET_NAME} PROPERTIES LINKER_LANGUAGE HIP)
605
- else ()
606
- add_library (${TARGET_NAME} STATIC ${_cmake_options} ${_generated_files} ${_sources} )
607
- set_target_properties (${TARGET_NAME} PROPERTIES LINKER_LANGUAGE CXX)
608
- target_link_libraries (${TARGET_NAME} ${ROCM_PATH} /hip/lib/libhip_hcc.so)
609
- find_fluid_modules(${TARGET_NAME} )
610
- endif ()
611
- if ("${hip_library_ops_DEPS} " MATCHES "ARCHIVE_START" )
612
- # Support linking flags: --whole-archive (Linux) / -force_load (MacOS).
613
- # WARNING: Please don't use ARCHIVE_START&ARCHIVE_END if TARGET_NAME will be linked by other libraries.
614
- target_circle_link_libraries(${TARGET_NAME} ${hip_library_ops_DEPS} )
615
- list (REMOVE_ITEM hip_library_ops_DEPS ARCHIVE_START ARCHIVE_END)
616
- else ()
617
- target_link_libraries (${TARGET_NAME} ${hip_library_ops_DEPS} )
618
- endif ()
619
- # cpplint code style
620
- foreach (source_file ${hip_library_ops_SRCS} )
621
- string (REGEX REPLACE "\\ .[^.]*$" "" source ${source_file} )
622
- if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR} /${source} .h)
623
- list (APPEND hip_library_ops_HEADERS ${CMAKE_CURRENT_SOURCE_DIR} /${source} .h)
624
- endif ()
625
- endforeach ()
626
- else (hip_library_ops_SRCS)
627
- if (hip_library_ops_DEPS)
628
- merge_static_libs(${TARGET_NAME} ${hip_library_ops_DEPS} )
629
- else ()
630
- message (FATAL "Please specify source file or library in nv_library." )
631
- endif ()
632
- endif (hip_library_ops_SRCS)
633
- endif ()
634
- endfunction (hip_library_ops)
635
-
636
588
function (hip_binary TARGET_NAME)
637
- if (WITH_ROCM_PLATFORM )
589
+ if (WITH_ROCM )
638
590
set (options "" )
639
591
set (oneValueArgs "" )
640
592
set (multiValueArgs SRCS DEPS)
641
593
cmake_parse_arguments (hip_binary "${options} " "${oneValueArgs} " "${multiValueArgs} " ${ARGN} )
642
- set_source_files_properties ( ${_sources} PROPERTIES HIP_SOURCE_PROPERTY_FORMAT 1)
594
+ # FindHIP.cmake defined hip_add_executable, HIP_SOURCE_PROPERTY_FORMAT is requried for .cc files
643
595
hip_add_executable(${TARGET_NAME} ${hip_binary_SRCS} )
644
596
if (hip_binary_DEPS)
645
597
target_link_libraries (${TARGET_NAME} ${hip_binary_DEPS} )
646
598
add_dependencies (${TARGET_NAME} ${hip_binary_DEPS} )
647
599
common_link(${TARGET_NAME} )
648
600
endif ()
649
601
endif ()
650
-
651
- check_coverage_opt(${TARGET_NAME} ${hip_binary_SRCS} )
652
-
653
602
endfunction (hip_binary)
654
603
655
604
function (hip_test TARGET_NAME)
656
- if (WITH_ROCM_PLATFORM AND WITH_TESTING)
657
- set (options "" )
605
+ # The environment variable `CI_SKIP_CPP_TEST` is used to skip the compilation
606
+ # and execution of test in CI. `CI_SKIP_CPP_TEST` is set to ON when no files
607
+ # other than *.py are modified.
608
+ if (WITH_ROCM AND WITH_TESTING AND NOT "$ENV{CI_SKIP_CPP_TEST} " STREQUAL "ON" )
658
609
set (oneValueArgs "" )
659
610
set (multiValueArgs SRCS DEPS)
660
611
cmake_parse_arguments (hip_test "${options} " "${oneValueArgs} " "${multiValueArgs} " ${ARGN} )
661
- set (_sources ${hip_test_SRCS} )
662
- set_source_files_properties (${_sources} PROPERTIES HIP_SOURCE_PROPERTY_FORMAT 1)
663
- HIP_PREPARE_TARGET_COMMANDS(${TARGET_NAME} OBJ _generated_files _source_files ${_sources} HIPCC_OPTIONS ${_hipcc_options} HCC_OPTIONS ${_hcc_options} NVCC_OPTIONS ${_nvcc_options} )
664
- if (_source_files)
665
- list (REMOVE_ITEM _sources ${_source_files} )
666
- endif ()
667
- add_executable (${TARGET_NAME} ${_cmake_options} ${_generated_files} ${_sources} )
668
- set_target_properties (${TARGET_NAME} PROPERTIES LINKER_LANGUAGE HIP)
612
+ # FindHIP.cmake defined hip_add_executable, HIP_SOURCE_PROPERTY_FORMAT is requried for .cc files
613
+ hip_add_executable(${TARGET_NAME} ${hip_test_SRCS} )
614
+ # "-pthread -ldl -lrt" is defined in CMAKE_CXX_LINK_EXECUTABLE
615
+ target_link_options (${TARGET_NAME} PRIVATE -pthread -ldl -lrt)
669
616
get_property (os_dependency_modules GLOBAL PROPERTY OS_DEPENDENCY_MODULES)
670
- target_link_libraries (${TARGET_NAME} ${hip_test_DEPS} paddle_gtest_main memory gtest gflags ${os_dependency_modules} )
671
- add_dependencies (${TARGET_NAME} ${hip_test_DEPS} paddle_gtest_main memory gtest gflags)
617
+ target_link_libraries (${TARGET_NAME} ${hip_test_DEPS} paddle_gtest_main lod_tensor memory gtest gflags glog ${os_dependency_modules} )
618
+ add_dependencies (${TARGET_NAME} ${hip_test_DEPS} paddle_gtest_main lod_tensor memory gtest gflags glog )
672
619
common_link(${TARGET_NAME} )
673
620
add_test (${TARGET_NAME} ${TARGET_NAME} )
621
+ set_property (TEST ${TARGET_NAME} PROPERTY ENVIRONMENT FLAGS_cpu_deterministic=true )
622
+ set_property (TEST ${TARGET_NAME} PROPERTY ENVIRONMENT FLAGS_init_allocated_mem=true )
623
+ set_property (TEST ${TARGET_NAME} PROPERTY ENVIRONMENT FLAGS_cudnn_deterministic=true )
674
624
endif ()
675
-
676
- check_coverage_opt(${TARGET_NAME} ${hip_test_SRCS} )
677
-
678
625
endfunction (hip_test)
679
626
680
627
function (go_library TARGET_NAME)
0 commit comments