Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
MIGraphX
Commits
efb502bf
Commit
efb502bf
authored
Sep 20, 2023
by
Brian Pickrell
Browse files
Added mutex locks in register_target.cpp and created a multithreading test. Fails.
parent
ac310ae5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
1 deletion
+39
-1
src/register_target.cpp
src/register_target.cpp
+19
-1
test/targets.cpp
test/targets.cpp
+20
-0
No files found.
src/register_target.cpp
View file @
efb502bf
...
...
@@ -21,6 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include <mutex>
#include <string>
#include <unordered_map>
#include <migraphx/register_target.hpp>
...
...
@@ -33,6 +34,9 @@ inline namespace MIGRAPHX_INLINE_NS {
void
store_target_lib
(
const
dynamic_loader
&
lib
)
{
static
std
::
vector
<
dynamic_loader
>
target_loader
;
std
::
mutex
mutex
;
std
::
unique_lock
<
std
::
mutex
>
lock
(
mutex
);
target_loader
.
emplace_back
(
lib
);
}
...
...
@@ -46,14 +50,28 @@ void register_target_init() { (void)target_map(); }
void
unregister_target
(
const
std
::
string
&
name
)
{
std
::
mutex
mutex
;
std
::
unique_lock
<
std
::
mutex
>
lock
(
mutex
);
assert
(
target_map
().
count
(
name
));
target_map
().
erase
(
name
);
}
void
register_target
(
const
target
&
t
)
{
target_map
()[
t
.
name
()]
=
t
;
}
void
register_target
(
const
target
&
t
)
{
std
::
mutex
mutex
;
std
::
unique_lock
<
std
::
mutex
>
lock
(
mutex
);
target_map
()[
t
.
name
()]
=
t
;
}
target
make_target
(
const
std
::
string
&
name
)
{
// debug
for
(
auto
pp
:
target_map
())
std
::
cout
<<
pp
.
first
<<
"
\n
"
;
std
::
mutex
mutex
;
std
::
unique_lock
<
std
::
mutex
>
lock
(
mutex
);
if
(
not
contains
(
target_map
(),
name
))
{
std
::
string
target_name
=
"libmigraphx_"
+
name
+
".so"
;
...
...
test/targets.cpp
View file @
efb502bf
...
...
@@ -23,6 +23,9 @@
*/
#include <migraphx/register_target.hpp>
#include <migraphx/target.hpp>
#include <migraphx/par_for.hpp>
#include <mutex>
#include <thread>
#include "test.hpp"
TEST_CASE
(
make_target
)
...
...
@@ -50,4 +53,21 @@ TEST_CASE(targets)
EXPECT
(
ts
.
size
()
>=
1
);
}
TEST_CASE
(
concurrent_targets
)
{
std
::
vector
<
std
::
thread
>
threads
;
for
(
auto
i
=
0u
;
i
<
10000
;
i
++
)
{
auto
thread_body
=
[]()
{
auto
ref_target
=
migraphx
::
make_target
(
"gpu"
);
migraphx
::
register_target
(
ref_target
);
};
threads
.
emplace_back
(
thread_body
);
}
for
(
auto
&
tt
:
threads
)
tt
.
join
();
}
int
main
(
int
argc
,
const
char
*
argv
[])
{
test
::
run
(
argc
,
argv
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment