Skip to content

Commit 6a52276

Browse files
committed
[Comgr] Explicitly describe data object mutation restrictions
Since the early days of the project we have effectively left the behavior when mutating a data object ambiguous once there is a chance that it has been shared. As the user has no direct way to know when an action takes an additional reference to an object, it is implementation-defined as to when mutation will affect objects which logically belong to other data sets. Attempt to clarify the situation by restricting mutation to newly-created data objects which have not been used as input to an action and have not been part of the output of an action. I haven't verified that every use of the library in our codebases is correct with these restrictions, but the current implementation of AMD_COMGR_ACTION_ADD_PRECOMPILED_HEADERS effectively assumes this already, and the natural useage pattern we have intended for the library conforms.
1 parent 3df8911 commit 6a52276

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

amd/comgr/include/amd_comgr.h.in

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ extern "C" {
112112
* passed to operations must be disjoint, together with all the @p
113113
* amd_comgr_data_t handles that have been added to it. The exception is that
114114
* the default device library data object handles can be non-disjoint as they
115-
* are imutable.
115+
* are immutable.
116116
*
117117
* The library supports generating and inspecting code objects that
118118
* contain machine code for a certain set of instruction set
@@ -135,6 +135,15 @@ extern "C" {
135135
* amd_comgr_do_action to perform an action specified by
136136
* @p amd_comgr_action_kind_t.
137137
*
138+
* Data objects are reference counted and are destroyed when the
139+
* reference count reaches 0. When a data object is created its
140+
* reference count is 1, it has 0 bytes of data, it has an empty name,
141+
* and it has no metadata.
142+
*
143+
* Mutating a data object is only permitted before it is used as part of
144+
* the input to an action. A data object which is the result of an action
145+
* must not be mutated.
146+
*
138147
* Some data objects can have associated metadata. There are
139148
* operations for querying this metadata.
140149
*
@@ -160,7 +169,6 @@ extern "C" {
160169
* include additional Comgr-specific informational messages.
161170
*/
162171

163-
164172
/** \defgroup symbol_versions_group Symbol Versions
165173
*
166174
* The names used for the shared library versioned symbols.
@@ -558,11 +566,6 @@ amd_comgr_get_isa_metadata(
558566
/**
559567
* @brief Create a data object that can hold data of a specified kind.
560568
*
561-
* Data objects are reference counted and are destroyed when the
562-
* reference count reaches 0. When a data object is created its
563-
* reference count is 1, it has 0 bytes of data, it has an empty name,
564-
* and it has no metadata.
565-
*
566569
* @param[in] kind The kind of data the object is intended to hold.
567570
*
568571
* @param[out] data A handle to the data object created. Its reference
@@ -583,12 +586,16 @@ amd_comgr_create_data(
583586
amd_comgr_data_kind_t kind,
584587
amd_comgr_data_t *data) AMD_COMGR_VERSION_1_8;
585588

586-
/**
589+
/**
587590
* @brief Indicate that no longer using a data object handle.
588591
*
589592
* The reference count of the associated data object is
590593
* decremented. If it reaches 0 it is destroyed.
591594
*
595+
* @note Although this may lead to the destruction of a data object, it is not
596+
* considered a mutation for the purposes of the restrictions described in @ref
597+
* codeobjectmanager.
598+
*
592599
* @param[in] data The data object to release.
593600
*
594601
* @retval ::AMD_COMGR_STATUS_SUCCESS The function has
@@ -634,6 +641,9 @@ amd_comgr_get_data_kind(
634641
* associated with the data object is also replaced which invalidates
635642
* all metadata handles to the old metadata.
636643
*
644+
* @warning This function mutates the data object; see @ref codeobjectmanager
645+
* for restrictions.
646+
*
637647
* @param[in] data The data object to update.
638648
*
639649
* @param[in] size The number of bytes in the data specified by @p bytes.
@@ -663,6 +673,9 @@ amd_comgr_set_data(
663673
* Internally this API calls amd_comgr_set_data and resets data object's
664674
* current state.
665675
*
676+
* @warning This function mutates the data object; see @ref codeobjectmanager
677+
* for restrictions.
678+
*
666679
* @param[in, out] data The data object to update.
667680
*
668681
* @param[in] file_descriptor The native file descriptor for an open file.
@@ -697,6 +710,9 @@ amd_comgr_set_data_from_file_slice(
697710
* name. The name may also be used for other data objects in log and
698711
* diagnostic output.
699712
*
713+
* @warning This function mutates the data object; see @ref codeobjectmanager
714+
* for restrictions.
715+
*
700716
* @param[in] data The data object to update.
701717
*
702718
* @param[in] name A null terminated string that specifies the name to

0 commit comments

Comments
 (0)