Adding concurrent init and init shutdown tests

Change-Id: Ifdbda16ae6c93a86373557f26eb414e40775d343


[ROCm/ROCR-Runtime commit: 8c8cd2dbd0]
Этот коммит содержится в:
srinivas Charupally
2018-04-23 12:53:24 +05:30
родитель 3cf867da15
Коммит ee40fbd721
5 изменённых файлов: 487 добавлений и 0 удалений
+154
Просмотреть файл
@@ -0,0 +1,154 @@
/*
* =============================================================================
* ROC Runtime Conformance Release License
* =============================================================================
* The University of Illinois/NCSA
* Open Source License (NCSA)
*
* Copyright (c) 2018, Advanced Micro Devices, Inc.
* All rights reserved.
*
* Developed by:
*
* AMD Research and AMD ROC Software Development
*
* Advanced Micro Devices, Inc.
*
* www.amd.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal with 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:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimers.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimers in
* the documentation and/or other materials provided with the distribution.
* - Neither the names of <Name of Development Group, Name of Institution>,
* nor the names of its contributors may be used to endorse or promote
* products derived from this Software without specific prior written
* permission.
*
* 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 CONTRIBUTORS 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 WITH THE SOFTWARE.
*
*/
#include <algorithm>
#include <iostream>
#include "suites/functional/concurrent_init.h"
#include "common/base_rocr_utils.h"
#include "common/common.h"
#include "common/helper_funcs.h"
#include "common/hsatimer.h"
#include "gtest/gtest.h"
#include "hsa/hsa.h"
#include "hsa/hsa_ext_finalize.h"
void* TestHSAInitFunction(void* args) {
// This function called for each thread
// This will initialize the HSA runtime.
hsa_status_t status;
// const char* err_str; // Local variable
// Initialize hsa runtime
status = hsa_init();
if (status != HSA_STATUS_SUCCESS) {
std::cout << "Failed" << std::endl;
}
pthread_exit(NULL);
}
static const int NumOfThreads = 100; // Number of thread to be created
#define RET_IF_HSA_ERR(err) { \
if ((err) != HSA_STATUS_SUCCESS) { \
const char* msg = 0; \
hsa_status_string(err, &msg); \
std::cout << "hsa api call failure at line " << __LINE__ << ", file: " << \
__FILE__ << ". Call returned " << err << std::endl; \
std::cout << msg << std::endl; \
return (err); \
} \
}
ConcurrentInitTest::ConcurrentInitTest(void) : TestBase() {
set_num_iteration(10); // Number of iterations to execute of the main test;
// This is a default value which can be overridden
// on the command line.
set_title("RocR Concurrent Init Test");
set_description("This test initializes HSA runtime concurrently");
}
// Any 1-time setup involving member variables used in the rest of the test
// should be done here.
ConcurrentInitTest::~ConcurrentInitTest(void) {
}
// Compare required profile for this test case with what we're actually
// running on
void ConcurrentInitTest::SetUp(void) {
return; // hsa runtime initalized pthread callback function
}
// Compare required profile for this test case with what we're actually
// running on
void ConcurrentInitTest::Run(void) {
if (!rocrtst::CheckProfile(this)) {
return;
}
TestBase::Run();
}
// Compare required profile for this test case with what we're actually
// running on
void ConcurrentInitTest::DisplayTestInfo(void) {
TestBase::DisplayTestInfo();
}
void ConcurrentInitTest::DisplayResults(void) const {
// Compare required profile for this test case with what we're actually
// running on
if (!rocrtst::CheckProfile(this)) {
return;
}
return;
}
void ConcurrentInitTest::Close() {
// This will close handles opened within rocrtst utility calls and call
// hsa_shut_down(), so it should be done after other hsa cleanup
TestBase::Close();
}
void ConcurrentInitTest::TestConcurrentInit(void) {
pthread_t ThreadId[NumOfThreads];
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); // Setting the attribute to PTHREAD_CREATE_JOINABLE
for (int Id = 0; Id < NumOfThreads; ++Id) { // This is to create threads concurrently
// HSA runtime will be initialized for each thread
int ThreadStatus = pthread_create(ThreadId + Id,
&attr, TestHSAInitFunction, &Id);
// Check if the thread is created successfully
if (ThreadStatus < 0) {
std::cout << Id << "Thread creation failed " << std::endl;
}
}
}
#undef RET_IF_HSA_ERR
+79
Просмотреть файл
@@ -0,0 +1,79 @@
/*
* =============================================================================
* ROC Runtime Conformance Release License
* =============================================================================
* The University of Illinois/NCSA
* Open Source License (NCSA)
*
* Copyright (c) 2018, Advanced Micro Devices, Inc.
* All rights reserved.
*
* Developed by:
*
* AMD Research and AMD ROC Software Development
*
* Advanced Micro Devices, Inc.
*
* www.amd.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal with 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:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimers.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimers in
* the documentation and/or other materials provided with the distribution.
* - Neither the names of <Name of Development Group, Name of Institution>,
* nor the names of its contributors may be used to endorse or promote
* products derived from this Software without specific prior written
* permission.
*
* 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 CONTRIBUTORS 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 WITH THE SOFTWARE.
*
*/
#ifndef ROCRTST_SUITES_FUNCTIONAL_CONCURRENT_INIT_H_
#define ROCRTST_SUITES_FUNCTIONAL_CONCURRENT_INIT_H_
#include <pthread.h>
#include "common/base_rocr.h"
#include "hsa/hsa.h"
#include "suites/test_common/test_base.h"
class ConcurrentInitTest : public TestBase {
public:
ConcurrentInitTest();
// @Brief: Destructor for the ConcurrentInitTest class
virtual ~ConcurrentInitTest();
// @Brief: Setup the environment for measurement
virtual void SetUp();
// @Brief: Core measurement execution
virtual void Run();
// @Brief: Clean up and retrive the resource
virtual void Close();
// @Brief: Display results
virtual void DisplayResults() const;
// @Brief: Display information about what this test does
virtual void DisplayTestInfo(void);
void TestConcurrentInit(void);
};
#endif // ROCRTST_SUITES_FUNCTIONAL_CONCURRENT_INIT_H_
+160
Просмотреть файл
@@ -0,0 +1,160 @@
/*
* =============================================================================
* ROC Runtime Conformance Release License
* =============================================================================
* The University of Illinois/NCSA
* Open Source License (NCSA)
*
* Copyright (c) 2018, Advanced Micro Devices, Inc.
* All rights reserved.
*
* Developed by:
*
* AMD Research and AMD ROC Software Development
*
* Advanced Micro Devices, Inc.
*
* www.amd.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal with 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:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimers.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimers in
* the documentation and/or other materials provided with the distribution.
* - Neither the names of <Name of Development Group, Name of Institution>,
* nor the names of its contributors may be used to endorse or promote
* products derived from this Software without specific prior written
* permission.
*
* 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 CONTRIBUTORS 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 WITH THE SOFTWARE.
*
*/
#include <algorithm>
#include <iostream>
#include "suites/functional/concurrent_init_shutdown.h"
#include "common/base_rocr_utils.h"
#include "common/common.h"
#include "common/helper_funcs.h"
#include "common/hsatimer.h"
#include "gtest/gtest.h"
#include "hsa/hsa.h"
#include "hsa/hsa_ext_finalize.h"
void* TestHSAInitShutdownFunction(void* args) {
// This is callback function for each thread
// This will initialize the HSA runtime and shutdown
hsa_status_t status;
// Initialize hsa runtime
status = hsa_init();
if (status != HSA_STATUS_SUCCESS) std::cout << "Failed" << std::endl;
// Shutdown hsa runtime
status = hsa_shut_down();
if (status != HSA_STATUS_SUCCESS) {
std::cout << "Failed" << std::endl;
}
pthread_exit(NULL);
}
static const int NumOfThreads = 100; // Number of thread to be created
#define RET_IF_HSA_ERR(err) { \
if ((err) != HSA_STATUS_SUCCESS) { \
const char* msg = 0; \
hsa_status_string(err, &msg); \
std::cout << "hsa api call failure at line " << __LINE__ << ", file: " << \
__FILE__ << ". Call returned " << err << std::endl; \
std::cout << msg << std::endl; \
return (err); \
} \
}
ConcurrentInitShutdownTest::ConcurrentInitShutdownTest(void) : TestBase() {
set_num_iteration(10); // Number of iterations to execute of the main test;
// This is a default value which can be overridden
// on the command line.
set_title("RocR Concurrent Init Test");
set_description("This test initializes HSA runtime concurrently");
}
// Any 1-time setup involving member variables used in the rest of the test
// should be done here.
ConcurrentInitShutdownTest::~ConcurrentInitShutdownTest(void) {
}
// Compare required profile for this test case with what we're actually
// running on
void ConcurrentInitShutdownTest::SetUp(void) {
return; // hsa runtime initalized pthread callback function
}
// Compare required profile for this test case with what we're actually
// running on
void ConcurrentInitShutdownTest::Run(void) {
if (!rocrtst::CheckProfile(this)) {
return;
}
TestBase::Run();
}
// Compare required profile for this test case with what we're actually
// running on
void ConcurrentInitShutdownTest::DisplayTestInfo(void) {
TestBase::DisplayTestInfo();
}
void ConcurrentInitShutdownTest::DisplayResults(void) const {
// Compare required profile for this test case with what we're actually
// running on
if (!rocrtst::CheckProfile(this)) {
return;
}
return;
}
void ConcurrentInitShutdownTest::Close() {
// This will close handles opened within rocrtst utility calls and call
// hsa_shut_down(), so it should be done after other hsa cleanup
TestBase::Close();
}
void ConcurrentInitShutdownTest::TestConcurrentInitShutdown(void) {
pthread_t ThreadId[NumOfThreads];
pthread_attr_t attr;
pthread_attr_init(&attr);
// Setting the attribute to PTHREAD_CREATE_JOINABLE
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
// This is to create threads concurrently
// HSA runtime will be initialized for each thread
for (int Id = 0; Id < NumOfThreads; ++Id) {
int ThreadStatus = pthread_create(ThreadId + Id, &attr,
TestHSAInitShutdownFunction, &Id);
// Check if the thread is created successfully
if (ThreadStatus < 0) {
std::cout << Id << "Thread creation failed " << std::endl;
}
}
}
#undef RET_IF_HSA_ERR
+78
Просмотреть файл
@@ -0,0 +1,78 @@
/*
* =============================================================================
* ROC Runtime Conformance Release License
* =============================================================================
* The University of Illinois/NCSA
* Open Source License (NCSA)
*
* Copyright (c) 2018, Advanced Micro Devices, Inc.
* All rights reserved.
*
* Developed by:
*
* AMD Research and AMD ROC Software Development
*
* Advanced Micro Devices, Inc.
*
* www.amd.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal with 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:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimers.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimers in
* the documentation and/or other materials provided with the distribution.
* - Neither the names of <Name of Development Group, Name of Institution>,
* nor the names of its contributors may be used to endorse or promote
* products derived from this Software without specific prior written
* permission.
*
* 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 CONTRIBUTORS 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 WITH THE SOFTWARE.
*
*/
#ifndef ROCRTST_SUITES_FUNCTIONAL_CONCURRENT_INIT_SHUTDOWN_H_
#define ROCRTST_SUITES_FUNCTIONAL_CONCURRENT_INIT_SHUTDOWN_H_
#include <pthread.h>
#include "common/base_rocr.h"
#include "hsa/hsa.h"
#include "suites/test_common/test_base.h"
class ConcurrentInitShutdownTest : public TestBase {
public:
ConcurrentInitShutdownTest();
// @Brief: Destructor for the ConcurrentInitShutdownTest class
virtual ~ConcurrentInitShutdownTest();
// @Brief: Setup the environment for measurement
virtual void SetUp();
// @Brief: Core measurement execution
virtual void Run();
// @Brief: Clean up and retrive the resource
virtual void Close();
// @Brief: Display results
virtual void DisplayResults() const;
// @Brief: Display information about what this test does
virtual void DisplayTestInfo(void);
void TestConcurrentInitShutdown(void);
};
#endif // ROCRTST_SUITES_FUNCTIONAL_CONCURRENT_INIT_SHUTDOWN_H_
+16
Просмотреть файл
@@ -59,6 +59,8 @@
#include "suites/test_common/test_case_template.h"
#include "suites/test_common/main.h"
#include "suites/test_common/test_common.h"
#include "suites/functional/concurrent_init.h"
#include "suites/functional/concurrent_init_shutdown.h"
#if ENABLE_SMI
#include "rocm_smi/rocm_smi.h"
@@ -148,6 +150,20 @@ TEST(rocrtstFunc, MemoryAccessTests) {
RunCustomTestEpilog(&mt);
}
TEST(rocrtstFunc, Concurrent_Init_Test) {
ConcurrentInitTest ci;
RunCustomTestProlog(&ci);
ci.TestConcurrentInit();
RunCustomTestEpilog(&ci);
}
TEST(rocrtstFunc, Concurrent_Init_Shutdown_Test) {
ConcurrentInitShutdownTest ci;
RunCustomTestProlog(&ci);
ci.TestConcurrentInitShutdown();
RunCustomTestEpilog(&ci);
}
TEST(rocrtstFunc, Memory_Max_Mem) {
MemoryTest mt;