Feb2021 GPU Package Update - GPU Package Files
This commit is contained in:
@ -53,6 +53,59 @@ class UCL_Texture {
|
||||
friend class UCL_Kernel;
|
||||
};
|
||||
|
||||
/// Class storing a const global memory reference
|
||||
class UCL_Const {
|
||||
public:
|
||||
UCL_Const() : _global_bytes(0), _active(false) {}
|
||||
~UCL_Const() { clear(); }
|
||||
/// Construct with a specified global reference
|
||||
inline UCL_Const(UCL_Program &prog, const char *global_name)
|
||||
{ get_global(prog,global_name); }
|
||||
/// Set the global reference for this object
|
||||
inline void get_global(UCL_Program &prog, const char *global_name) {
|
||||
if (_active) {
|
||||
CL_DESTRUCT_CALL(clReleaseContext(_context));
|
||||
CL_DESTRUCT_CALL(clReleaseCommandQueue(_cq));
|
||||
}
|
||||
_active = true;
|
||||
_context = prog._context;
|
||||
_cq = prog._cq;
|
||||
CL_SAFE_CALL(clRetainContext(_context));
|
||||
CL_SAFE_CALL(clRetainCommandQueue(_cq));
|
||||
}
|
||||
/// Copy from array on host to const memory
|
||||
template <class numtyp>
|
||||
inline void update_device(UCL_H_Vec<numtyp> &src, const int numel) {
|
||||
const int bytes=numel*sizeof(numtyp);
|
||||
if (_global_bytes < bytes) {
|
||||
if (_global_bytes) CL_SAFE_CALL(clReleaseMemObject(_global));
|
||||
cl_int e;
|
||||
_global = clCreateBuffer(_context, CL_MEM_READ_ONLY, bytes, NULL, &e);
|
||||
CL_SAFE_CALL(e);
|
||||
}
|
||||
CL_SAFE_CALL(clEnqueueWriteBuffer(_cq, _global, CL_FALSE, 0, bytes,
|
||||
(void *)src.begin(), 0, NULL, NULL));
|
||||
}
|
||||
/// Get device ptr associated with object
|
||||
inline const cl_mem * begin() const { return &_global; }
|
||||
inline void clear() {
|
||||
if (_global_bytes) CL_SAFE_CALL(clReleaseMemObject(_global));
|
||||
if (_active) {
|
||||
CL_DESTRUCT_CALL(clReleaseContext(_context));
|
||||
CL_DESTRUCT_CALL(clReleaseCommandQueue(_cq));
|
||||
}
|
||||
_global_bytes=0;
|
||||
_active=false;
|
||||
}
|
||||
|
||||
private:
|
||||
cl_mem _global;
|
||||
size_t _global_bytes;
|
||||
cl_context _context;
|
||||
cl_command_queue _cq;
|
||||
bool _active;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user