Refactor for stream->_av.

- move _av into stream critical section.  ( HCC accelerator_view is not
  thread-safe but HIP steram is. )
- Refactored many places in code that need to acquire critical section.
some were previously thread races, ie enqueueing marker.

-remove support for GRID_LAUNCH_VERSION < 20
-Enable USE_AV_COPY based on HCC work-week.
- Review hipModule docs, some calrity/editing.

Change-Id: I3ce7c25ece048c3504f55ecd4683e506bb1fc8b6
Tento commit je obsažen v:
Ben Sander
2016-08-30 17:29:50 -05:00
rodič cd3a0a2d61
revize e76a272d48
7 změnil soubory, kde provedl 128 přidání a 183 odebrání
+34 -23
Zobrazit soubor
@@ -32,7 +32,7 @@ THE SOFTWARE.
// #define USE_MEMCPYTOSYMBOL
//
//Use the new HCC accelerator_view::copy instead of am_copy
#define USE_AV_COPY 0
#define USE_AV_COPY (__hcc_workweek__ >= 16351)
// Compile peer-to-peer support.
// >= 2 : use HCC hc:accelerator::get_is_peer
@@ -353,18 +353,36 @@ struct LockedBase {
};
class ihipModule_t{
public:
hsa_executable_t executable;
hsa_code_object_t object;
std::string fileName;
void *ptr;
size_t size;
};
class ihipFunction_t{
public:
hsa_executable_symbol_t kernel_symbol;
uint64_t kernel;
};
template <typename MUTEX_TYPE>
class ihipStreamCriticalBase_t : public LockedBase<MUTEX_TYPE>
{
public:
ihipStreamCriticalBase_t() :
ihipStreamCriticalBase_t(hc::accelerator_view av) :
_last_command_type(ihipCommandCopyH2H),
_last_copy_signal(NULL),
_signalCursor(0),
_oldest_live_sig_id(1),
_streamSigId(0),
_kernelCnt(0),
_signalCnt(0)
_signalCnt(0),
_av(av)
{
_signalPool.resize(HIP_STREAM_SIGNALS > 0 ? HIP_STREAM_SIGNALS : 1);
};
@@ -395,27 +413,14 @@ public:
// 2 are required if a barrier packet is inserted.
uint32_t _kernelCnt; // Count of inflight kernels in this stream. Reset at ::wait().
SIGSEQNUM _streamSigId; // Monotonically increasing unique signal id.
hc::accelerator_view _av;
};
typedef ihipStreamCriticalBase_t<StreamMutex> ihipStreamCritical_t;
typedef LockedAccessor<ihipStreamCritical_t> LockedAccessor_StreamCrit_t;
class ihipModule_t{
public:
hsa_executable_t executable;
hsa_code_object_t object;
std::string fileName;
void *ptr;
size_t size;
};
class ihipFunction_t{
public:
hsa_executable_symbol_t kernel_symbol;
uint64_t kernel;
};
// Internal stream structure.
class ihipStream_t {
@@ -431,16 +436,23 @@ typedef uint64_t SeqNum_t ;
void copyAsync(void* dst, const void* src, size_t sizeBytes, unsigned kind);
int preCopyCommand(LockedAccessor_StreamCrit_t &crit, ihipSignal_t *lastCopy, hsa_signal_t *waitSignal, ihipCommand_t copyType);
//---
// Thread-safe accessors - these acquire / release mutex:
bool lockopen_preKernelCommand();
// Member functions that begin with locked_ are thread-safe accessors - these acquire / release the critical mutex.
LockedAccessor_StreamCrit_t lockopen_preKernelCommand();
void lockclose_postKernelCommand(hc::completion_future &kernel_future);
int preCopyCommand(LockedAccessor_StreamCrit_t &crit, ihipSignal_t *lastCopy, hsa_signal_t *waitSignal, ihipCommand_t copyType);
void locked_reclaimSignals(SIGSEQNUM sigNum);
void locked_wait(bool assertQueueEmpty=false);
SIGSEQNUM locked_lastCopySeqId() {LockedAccessor_StreamCrit_t crit(_criticalData); return lastCopySeqId(crit); };
hc::accelerator_view* locked_getAv() { LockedAccessor_StreamCrit_t crit(_criticalData); return &(crit->_av); };
void locked_waitEvent(hipEvent_t event);
void locked_recordEvent(hipEvent_t event);
//---
// Use this if we already have the stream critical data mutex:
void wait(LockedAccessor_StreamCrit_t &crit, bool assertQueueEmpty=false);
@@ -462,7 +474,6 @@ public:
//---
//Public member vars - these are set at initialization and never change:
SeqNum_t _id; // monotonic sequence ID
hc::accelerator_view _av;
unsigned _flags;
+1 -18
Zobrazit soubor
@@ -50,9 +50,8 @@ THE SOFTWARE.
#if defined (GRID_LAUNCH_VERSION) and (GRID_LAUNCH_VERSION >= 20)
// Use field names for grid_launch 2.0 structure, if HCC supports GL 2.0.
#define USE_GRID_LAUNCH_20 1
#else
#define USE_GRID_LAUNCH_20 0
#error (HCC must support GRID_LAUNCH_20)
#endif
#define HIP_LAUNCH_PARAM_BUFFER_POINTER ((void*) 0x01)
@@ -633,7 +632,6 @@ extern void ihipPostLaunchKernel(hipStream_t stream, grid_launch_parm &lp);
#define KNRM "\x1B[0m"
#define KGRN "\x1B[32m"
#if USE_GRID_LAUNCH_20
#define hipLaunchKernel(_kernelName, _numBlocks3D, _blockDim3D, _groupMemBytes, _stream, ...) \
do {\
grid_launch_parm lp;\
@@ -645,21 +643,6 @@ do {\
_kernelName (lp, ##__VA_ARGS__);\
ihipPostLaunchKernel(trueStream, lp);\
} while(0)
#else
#define hipLaunchKernel(_kernelName, _numBlocks3D, _blockDim3D, _groupMemBytes, _stream, ...) \
do {\
grid_launch_parm lp;\
lp.groupMemBytes = _groupMemBytes; \
hipStream_t trueStream = (ihipPreLaunchKernel(_stream, _numBlocks3D, _blockDim3D, &lp)); \
if (HIP_TRACE_API) {\
fprintf(stderr, KGRN "<<hip-api: hipLaunchKernel '%s' gridDim:(%d,%d,%d) groupDim:(%d,%d,%d) groupMem:+%d stream=%p\n" KNRM, \
#_kernelName, lp.gridDim.x, lp.gridDim.y, lp.gridDim.z, lp.groupDim.x, lp.groupDim.y, lp.groupDim.z, lp.groupMemBytes, (void*)(_stream));\
}\
_kernelName (lp, ##__VA_ARGS__);\
ihipPostLaunchKernel(trueStream, lp);\
} while(0)
#endif
#elif defined (__HCC_C__)
+9 -7
Zobrazit soubor
@@ -1307,7 +1307,7 @@ hipError_t hipDriverGetVersion(int *driverVersion) ;
hipError_t hipModuleLoad(hipModule_t *module, const char *fname);
/**
* @brief Freeing the module
* @brief Frees the module
*
* @param [in] module
*
@@ -1319,7 +1319,7 @@ hipError_t hipModuleLoad(hipModule_t *module, const char *fname);
hipError_t hipModuleUnload(hipModule_t module);
/**
* @brief Function with kname will be extracted present in module
* @brief Function with kname will be extracted if present in module
*
* @param [in] module
* @param [in] kname
@@ -1330,19 +1330,20 @@ hipError_t hipModuleUnload(hipModule_t module);
hipError_t hipModuleGetFunction(hipFunction_t *function, hipModule_t module, const char *kname);
/**
* @brief returns device memory pointer and size of the kernel present in the module with symbol - name
* @brief returns device memory pointer and size of the kernel present in the module with symbol @p name
*
* @param [in] moodule
* @param [in] name
* @param [out] dptr
* @param [out[ bytes
* @param [in] hmod
* @param [in] name
*
* @returns hipSuccess, hipErrorInvalidValue, hipErrorNotInitialized
*/
hipError_t hipModuleGetGlobal(hipDeviceptr_t *dptr, size_t *bytes, hipModule_t hmod, const char *name);
/**
* @brief builds module from code object which resides in host memory. And image is pointer to that location.
* @brief builds module from code object which resides in host memory. Image is pointer to that location.
*
* @param [in] image
* @param [out] module
@@ -1351,8 +1352,9 @@ hipError_t hipModuleGetGlobal(hipDeviceptr_t *dptr, size_t *bytes, hipModule_t h
*/
hipError_t hipModuleLoadData(hipModule_t *module, const void *image);
/**
* @brief launches kernel f with launch parameters and shared memory on stream with arguments passed to kerneelparams or extra
* @brief launches kernel f with launch parameters and shared memory on stream with arguments passed to kernelparams or extra
*
* @param [in[ f
* @param [in] gridDimX