Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmake: generate export header function #2348

Merged
merged 5 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions cmake/ExportHeader.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
################################################################################
#
# MIT License
#
# Copyright (c) 2023 Advanced Micro Devices, Inc.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
################################################################################

if(COMMAND miopen_generate_export_header)
return()
endif()

include(GenerateExportHeader)

function(miopen_generate_export_header TARGET)
cmake_parse_arguments(PARSE "" "DIRECTORY" "" ${ARGN})
if(PARSE_DIRECTORY)
set(__directory ${PARSE_DIRECTORY})
else()
string(REPLACE "_" "/" __directory ${TARGET})
string(TOLOWER ${__directory} __directory)
endif()
set(__file_name ${CMAKE_BINARY_DIR}/include/${__directory}/export.h)
generate_export_header(${TARGET} EXPORT_FILE_NAME ${__file_name})
target_include_directories(${TARGET} PUBLIC $<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include>)
rocm_install(FILES ${__file_name} DESTINATION include/${__directory})
endfunction()
4 changes: 2 additions & 2 deletions driver/conv_driver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@
#include <boost/optional.hpp>

// Declare hidden function for MIGraphX to smoke test it.
extern "C" miopenStatus_t miopenHiddenSetConvolutionFindMode(miopenConvolutionDescriptor_t convDesc,
int findMode);
extern "C" MIOPEN_EXPORT miopenStatus_t
miopenHiddenSetConvolutionFindMode(miopenConvolutionDescriptor_t convDesc, int findMode);

#define WORKAROUND_ISSUE_2176 1 // https://github.com/AMDComputeLibraries/MLOpen/issues/2176

Expand Down
78 changes: 43 additions & 35 deletions include/miopen/miopen.h
Original file line number Diff line number Diff line change
Expand Up @@ -5245,7 +5245,7 @@ MIOPEN_EXPORT miopenStatus_t miopenCreateConvProblem(miopenProblem_t* problem,
* @param problem Problem to destroy
* @return miopenStatus_t
*/
miopenStatus_t miopenDestroyProblem(miopenProblem_t problem);
MIOPEN_EXPORT miopenStatus_t miopenDestroyProblem(miopenProblem_t problem);

/*! @brief Sets a tensor descriptor for the specified argument.
*
Expand All @@ -5254,9 +5254,10 @@ miopenStatus_t miopenDestroyProblem(miopenProblem_t problem);
* @param descriptor Tensor descriptor to set
* @return miopenStatus_t
*/
miopenStatus_t miopenSetProblemTensorDescriptor(miopenProblem_t problem,
miopenTensorArgumentId_t id,
const miopenTensorDescriptor_t descriptor);
MIOPEN_EXPORT miopenStatus_t
miopenSetProblemTensorDescriptor(miopenProblem_t problem,
miopenTensorArgumentId_t id,
const miopenTensorDescriptor_t descriptor);

/*! @brief The miopenFindOptions allows the user to configure how find will be used.
*/
Expand All @@ -5267,31 +5268,31 @@ MIOPEN_DECLARE_OBJECT(miopenFindOptions);
* @param options Pointer to options object to initialze
* @return miopenStatus_t
*/
miopenStatus_t miopenCreateFindOptions(miopenFindOptions_t* options);
MIOPEN_EXPORT miopenStatus_t miopenCreateFindOptions(miopenFindOptions_t* options);

/*! @brief Destroys miopenFindOptions object.
*
* @param options Options object to destroy
* @return miopenStatus_t
*/
miopenStatus_t miopenDestroyFindOptions(miopenFindOptions_t options);
MIOPEN_EXPORT miopenStatus_t miopenDestroyFindOptions(miopenFindOptions_t options);

/*! @brief Sets the tuning find option. Default value is zero.
*
* @param options Options object to update
* @param value Value of zero means no tuning, value of one means tuning enabled
* @return miopenStatus_t
*/
miopenStatus_t miopenSetFindOptionTuning(miopenFindOptions_t options, int value);
MIOPEN_EXPORT miopenStatus_t miopenSetFindOptionTuning(miopenFindOptions_t options, int value);

/*! @brief Sets the results order find option. Default value is miopenFindResultsOrderByTime.
*
* @param options Options object to update
* @param value Specifies what order should find results have
* @return miopenStatus_t
*/
miopenStatus_t miopenSetFindOptionResultsOrder(miopenFindOptions_t options,
miopenFindResultsOrder_t value);
MIOPEN_EXPORT miopenStatus_t miopenSetFindOptionResultsOrder(miopenFindOptions_t options,
miopenFindResultsOrder_t value);

/*! @brief Sets the workspace limit find option. Default value is maximum of size_t
*
Expand All @@ -5300,7 +5301,8 @@ miopenStatus_t miopenSetFindOptionResultsOrder(miopenFindOptions_t options,
* would be ignored.
* @return miopenStatus_t
*/
miopenStatus_t miopenSetFindOptionWorkspaceLimit(miopenFindOptions_t options, size_t value);
MIOPEN_EXPORT miopenStatus_t miopenSetFindOptionWorkspaceLimit(miopenFindOptions_t options,
size_t value);

/*! @brief Attaches the preallocated workspace to find options. Allocated by the library by default.
*
Expand All @@ -5309,8 +5311,9 @@ miopenStatus_t miopenSetFindOptionWorkspaceLimit(miopenFindOptions_t options, si
* @param size Specifies the size of the buffer passed
* @return miopenStatus_t
*/
miopenStatus_t
miopenSetFindOptionPreallocatedWorkspace(miopenFindOptions_t options, void* buffer, size_t size);
MIOPEN_EXPORT miopenStatus_t miopenSetFindOptionPreallocatedWorkspace(miopenFindOptions_t options,
void* buffer,
size_t size);

/*! @brief Attaches a preallocated tensor to find options. If not used, buffers are allocated by
* MIOpen internally, which is not recommended.
Expand All @@ -5320,9 +5323,9 @@ miopenSetFindOptionPreallocatedWorkspace(miopenFindOptions_t options, void* buff
* @param buffer Specifies the tensor for find call
* @return miopenStatus_t
*/
miopenStatus_t miopenSetFindOptionPreallocatedTensor(miopenFindOptions_t options,
miopenTensorArgumentId_t id,
void* buffer);
MIOPEN_EXPORT miopenStatus_t miopenSetFindOptionPreallocatedTensor(miopenFindOptions_t options,
miopenTensorArgumentId_t id,
void* buffer);

/*! @brief The miopenSolution object describes a prepared solution.
*/
Expand All @@ -5339,12 +5342,12 @@ MIOPEN_DECLARE_OBJECT(miopenSolution);
* @param maxSolutions Limits the amount of results
* @return miopenStatus_t
*/
miopenStatus_t miopenFindSolutions(miopenHandle_t handle,
miopenProblem_t problem,
miopenFindOptions_t options,
miopenSolution_t* solutions,
size_t* numSolutions,
size_t maxSolutions);
MIOPEN_EXPORT miopenStatus_t miopenFindSolutions(miopenHandle_t handle,
miopenProblem_t problem,
miopenFindOptions_t options,
miopenSolution_t* solutions,
size_t* numSolutions,
size_t maxSolutions);

/*! @brief Values of a tensor argument for the miopenRunSolution function.
*/
Expand Down Expand Up @@ -5375,19 +5378,19 @@ struct miopenTensorArgument_t
* @param workspaceSize Size of the workspace buffer
* @return miopenStatus_t
*/
miopenStatus_t miopenRunSolution(miopenHandle_t handle,
miopenSolution_t solution,
size_t nInputs,
const miopenTensorArgument_t* tensors,
void* workspace,
size_t workspaceSize);
MIOPEN_EXPORT miopenStatus_t miopenRunSolution(miopenHandle_t handle,
miopenSolution_t solution,
size_t nInputs,
const miopenTensorArgument_t* tensors,
void* workspace,
size_t workspaceSize);

/*! @brief Destroys solution object.
*
* @param solution Solution to destroy
* @return miopenStatus_t
*/
miopenStatus_t miopenDestroySolution(miopenSolution_t solution);
MIOPEN_EXPORT miopenStatus_t miopenDestroySolution(miopenSolution_t solution);

/*! @brief Loads solution object from binary data.
*
Expand All @@ -5396,55 +5399,60 @@ miopenStatus_t miopenDestroySolution(miopenSolution_t solution);
* @param size Size of the solution blob
* @return miopenStatus_t
*/
miopenStatus_t miopenLoadSolution(miopenSolution_t* solution, const char* data, size_t size);
MIOPEN_EXPORT miopenStatus_t miopenLoadSolution(miopenSolution_t* solution,
const char* data,
size_t size);

/*! @brief Saves a solution object as binary data.
*
* @param solution Solution to save
* @param data Pointer to a buffer to save soltuion to
* @return miopenStatus_t
*/
miopenStatus_t miopenSaveSolution(miopenSolution_t solution, char* data);
MIOPEN_EXPORT miopenStatus_t miopenSaveSolution(miopenSolution_t solution, char* data);

/*! @brief Reads the expected size of a solution.
*
* @param solution Solution to get size
* @param size Pointer to a location where to write the size of the solution blob
* @return miopenStatus_t
*/
miopenStatus_t miopenGetSolutionSize(miopenSolution_t solution, size_t* size);
MIOPEN_EXPORT miopenStatus_t miopenGetSolutionSize(miopenSolution_t solution, size_t* size);

/*! @brief Reads the amount of workspace required to exectute the solution.
*
* @param solution Solution to get required workspace size
* @param workspaceSize Pointer to a location where to write the workspace size
* @return miopenStatus_t
*/
miopenStatus_t miopenGetSolutionWorkspaceSize(miopenSolution_t solution, size_t* workspaceSize);
MIOPEN_EXPORT miopenStatus_t miopenGetSolutionWorkspaceSize(miopenSolution_t solution,
size_t* workspaceSize);

/*! @brief Reads the time spent to execute the solution the last it was run.
*
* @param solution Solution to get exection time
* @param time Pointer to a location where to write the execution time
* @return miopenStatus_t
*/
miopenStatus_t miopenGetSolutionTime(miopenSolution_t solution, float* time);
MIOPEN_EXPORT miopenStatus_t miopenGetSolutionTime(miopenSolution_t solution, float* time);

/*! @brief Reads id of the solver referred by the solution.
*
* @param solution Solution to get solver id from
* @param solverId Pointer to a location where to write the solver id
* @return miopenStatus_t
*/
miopenStatus_t miopenGetSolutionSolverId(miopenSolution_t solution, uint64_t* solverId);
MIOPEN_EXPORT miopenStatus_t miopenGetSolutionSolverId(miopenSolution_t solution,
uint64_t* solverId);

/*! @brief Gets the convolution algorithm implemented by a solver.
*
* @param solverId Solver id to get convolution algorithm of
* @param result Pointer to a location where to write the algorithm
* @return miopenStatus_t
*/
miopenStatus_t miopenGetSolverIdConvAlgorithm(uint64_t solverId, miopenConvAlgorithm_t* result);
MIOPEN_EXPORT miopenStatus_t miopenGetSolverIdConvAlgorithm(uint64_t solverId,
miopenConvAlgorithm_t* result);

/** @} */
// CLOSEOUT find2 DOXYGEN GROUP
Expand Down
13 changes: 2 additions & 11 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

cmake_policy(SET CMP0057 NEW)

include (GenerateExportHeader)
include(ExportHeader)
if(MIOPEN_ENABLE_SQLITE)
add_subdirectory(sqlite)
endif()
Expand Down Expand Up @@ -718,9 +718,7 @@ target_include_directories(MIOpen SYSTEM PRIVATE ${BZIP2_INCLUDE_DIR})
# Workaround : change in rocm-cmake was causing linking error so had to add ${CMAKE_DL_LIBS}
# We can remove ${CMAKE_DL_LIBS} once root cause is identified.
target_link_libraries(MIOpen PRIVATE ${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT} ${BZIP2_LIBRARIES} ${MIOPEN_CK_LINK_FLAGS})
generate_export_header(MIOpen
EXPORT_FILE_NAME ${PROJECT_BINARY_DIR}/include/miopen/export.h
)
miopen_generate_export_header(MIOpen)

if(MIOPEN_ENABLE_AI_KERNEL_TUNING OR MIOPEN_ENABLE_AI_IMMED_MODE_FALLBACK)
find_path(FDEEP_INCLUDE_DIR "fdeep/fdeep.hpp")
Expand Down Expand Up @@ -802,13 +800,6 @@ endif()

target_link_libraries(MIOpen PRIVATE nlohmann_json::nlohmann_json)

if(WIN32 AND NOT MSVC)
if(BUILD_DEV)
target_link_libraries(MIOpen PUBLIC -Wl,-export-all-symbols -Wl,-exclude-symbols=_Unwind_Resume)
endif()
target_link_libraries(MIOpen PUBLIC -Wl,--whole-archive -lgcc -lstdc++-6 -Wl,--no-whole-archive -Wl,--allow-multiple-definition)
endif()

target_internal_library(MIOpen
Boost::filesystem
)
Expand Down
8 changes: 6 additions & 2 deletions src/convolution_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ extern "C" miopenStatus_t miopenGetConvolutionFindMode(const miopenConvolutionDe
}

// Hidden C++ functions for MIGraphX.
extern "C" miopenStatus_t miopenHiddenSetConvolutionFindMode(miopenConvolutionDescriptor_t convDesc,
int findMode)
extern "C" MIOPEN_EXPORT miopenStatus_t
miopenHiddenSetConvolutionFindMode(miopenConvolutionDescriptor_t convDesc, int findMode)
{
return miopen::try_([&] {
miopen::deref(convDesc).findMode.Set(static_cast<miopen::FindMode::Values>(findMode));
Expand Down Expand Up @@ -393,6 +393,7 @@ miopenConvolutionForwardGetWorkSpaceSize(miopenHandle_t handle,
namespace miopen {
namespace debug {

MIOPEN_EXPORT
void LogCmdConvolution(const miopen::TensorDescriptor& x,
const miopen::TensorDescriptor& w,
const miopen::ConvolutionDescriptor& conv,
Expand All @@ -407,6 +408,7 @@ void LogCmdConvolution(const miopen::TensorDescriptor& x,
}
}

MIOPEN_EXPORT
void LogCmdFindConvolution(const miopen::TensorDescriptor& x,
const miopen::TensorDescriptor& w,
const miopen::ConvolutionDescriptor& conv,
Expand All @@ -421,6 +423,7 @@ void LogCmdFindConvolution(const miopen::TensorDescriptor& x,
}
}

MIOPEN_EXPORT
void LogCmdConvolution(const miopenTensorDescriptor_t& xDesc,
const miopenTensorDescriptor_t& wDesc,
const miopenConvolutionDescriptor_t& convDesc,
Expand All @@ -437,6 +440,7 @@ void LogCmdConvolution(const miopenTensorDescriptor_t& xDesc,
}
}

MIOPEN_EXPORT
void LogCmdFindConvolution(const miopenTensorDescriptor_t& xDesc,
const miopenTensorDescriptor_t& wDesc,
const miopenConvolutionDescriptor_t& convDesc,
Expand Down
1 change: 0 additions & 1 deletion src/tensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,6 @@ void from_json(const nlohmann::json& j, TensorDescriptor& descriptor)
} // namespace miopen

// TODO(paul): Remove
junliume marked this conversation as resolved.
Show resolved Hide resolved
MIOPEN_EXPORT
int miopenGetTensorIndex(miopenTensorDescriptor_t tensorDesc, std::initializer_list<int> indices)
{
return miopen::deref(tensorDesc).GetIndex(indices);
Expand Down
2 changes: 2 additions & 0 deletions test/gtest/log.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ struct OperatorArgs;
namespace debug {
// Copy of function declaration that is in miopen.
// This is for testing purpose only.
MIOPEN_EXPORT
void LogCmdConvolution(const miopenTensorDescriptor_t& xDesc,
const miopenTensorDescriptor_t& wDesc,
const miopenConvolutionDescriptor_t& convDesc,
Expand All @@ -49,6 +50,7 @@ void LogCmdConvolution(const miopenTensorDescriptor_t& xDesc,
bool is_immediate);
// Copy of function declaration that is in miopen.
// This is for testing purpose only.
MIOPEN_EXPORT
void LogCmdFindConvolution(const miopenTensorDescriptor_t& xDesc,
const miopenTensorDescriptor_t& wDesc,
const miopenConvolutionDescriptor_t& convDesc,
Expand Down