clsparseStatus validateMemObject( cl_mem mem, size_t required_size) { #ifndef NDEBUG //check if valid mem object, cl_mem_object_type mem_type = 0; clGetMemObjectInfo(mem, CL_MEM_TYPE, sizeof(mem_type), &mem_type, NULL); if (mem_type != CL_MEM_OBJECT_BUFFER) { return clsparseInvalidMemObj; } //check if mem object have valid required size if (required_size > 0) { size_t current_size; clGetMemObjectInfo(mem, CL_MEM_SIZE, sizeof(current_size), ¤t_size, NULL); std::cout << "[validateMemObject] Buffer size: " << current_size << " bytes. "; std::cout << "Required size: " << required_size << " bytes." << std::endl; if (current_size < required_size) return clsparseInvalidSize; } #endif return clsparseSuccess; }
cl_mem mwDuplicateBuffer(CLInfo* ci, cl_mem buf) { cl_mem bufCopy; size_t size; cl_mem_flags flags; cl_int err; cl_event ev; if (!buf) { return NULL; } err = clGetMemObjectInfo(buf, CL_MEM_FLAGS, sizeof(flags), &flags, NULL); if (err != CL_SUCCESS) { mwPerrorCL(err, "Failed to get memory flags for buffer duplication"); return NULL; } err = clGetMemObjectInfo(buf, CL_MEM_SIZE, sizeof(size), &size, NULL); if (err != CL_SUCCESS) { mwPerrorCL(err, "Failed to get memory size for buffer duplication"); return NULL; } /* We may have initialized that one from a host pointer, but not this one */ flags ^= CL_MEM_COPY_HOST_PTR; /* Create a copy of the same size */ bufCopy = clCreateBuffer(ci->clctx, flags, size, NULL, &err); if (err != CL_SUCCESS) { mwPerrorCL(err, "Failed to create copy buffer of size "ZU, size); return NULL; } err = clEnqueueCopyBuffer(ci->queue, buf, bufCopy, 0, 0, size, 0, NULL, &ev); if (err != CL_SUCCESS) { mwPerrorCL(err, "Failed to enqueue buffer copy of size"ZU, size); clReleaseMemObject(bufCopy); return NULL; } err = mwWaitReleaseEvent(&ev); if (err != CL_SUCCESS) { mwPerrorCL(err, "Failed to wait for buffer copy"); clReleaseMemObject(bufCopy); return NULL; } return bufCopy; }
void print_cl_mem_info(const cl_mem& mem){ CLInfo* clinfo = CLInfo::instance(); if (!clinfo->initialized()) return; size_t mem_size, bytes_written; cl_mem_object_type mem_type; cl_int err; err = clGetMemObjectInfo(mem, CL_MEM_SIZE, sizeof(size_t), &mem_size, &bytes_written); if (error_cl(err, "clGetMemObjectInfo CL_MEM_SIZE")) return; std::cerr << "CL mem object size: " << mem_size << std::endl; err = clGetMemObjectInfo(mem, CL_MEM_TYPE, sizeof(cl_mem_object_type), &mem_type, &bytes_written); if (error_cl(err, "clGetMemObjectInfo CL_MEM_TYPE")) return; std::cerr << "CL mem type: "; switch (mem_type) { case CL_MEM_OBJECT_BUFFER: std::cerr << "CL_MEM_OBJECT_BUFFER" << std::endl; break; case CL_MEM_OBJECT_IMAGE2D: std::cerr << "CL_MEM_OBJECT_IMAGE2D" << std::endl; break; case CL_MEM_OBJECT_IMAGE3D: std::cerr << "CL_MEM_OBJECT_IMAGE3D" << std::endl; break; default: std::cerr << "UNKNOWN" << std::endl; break; } }
/* static */ cl_int MemoryObjectWrapper::memoryObjectInfoHelper (Wrapper const* aInstance, int aName, size_t aSize, void* aValueOut, size_t* aSizeOut) { cl_int err = CL_SUCCESS; MemoryObjectWrapper const* instance = dynamic_cast<MemoryObjectWrapper const*>(aInstance); VALIDATE_ARG_POINTER (instance, &err, err); return clGetMemObjectInfo (instance->getWrapped (), aName, aSize, aValueOut, aSizeOut); }
void b3LauncherCL::setBuffers( b3BufferInfoCL* buffInfo, int n ) { for(int i=0; i<n; i++) { if (m_enableSerialization) { b3KernelArgData kernelArg; kernelArg.m_argIndex = m_idx; kernelArg.m_isBuffer = 1; kernelArg.m_clBuffer = buffInfo[i].m_clBuffer; cl_mem_info param_name = CL_MEM_SIZE; size_t param_value; size_t sizeInBytes = sizeof(size_t); size_t actualSizeInBytes; cl_int err; err = clGetMemObjectInfo ( kernelArg.m_clBuffer, param_name, sizeInBytes, ¶m_value, &actualSizeInBytes); b3Assert( err == CL_SUCCESS ); kernelArg.m_argSizeInBytes = param_value; m_kernelArguments.push_back(kernelArg); m_serializationSizeInBytes+= sizeof(b3KernelArgData); m_serializationSizeInBytes+=param_value; } cl_int status = clSetKernelArg( m_kernel, m_idx++, sizeof(cl_mem), &buffInfo[i].m_clBuffer); b3Assert( status == CL_SUCCESS ); } }
static VALUE rcl_mem_info(VALUE self, VALUE param_name) { EXPECT_RCL_CONST(param_name); cl_mem_info mi = FIX2UINT(param_name); cl_mem m = MemoryPtr(self); intptr_t param_value; cl_int res = clGetMemObjectInfo(m, mi, sizeof(intptr_t), ¶m_value, NULL); CHECK_AND_RAISE(res); switch (mi) { case CL_MEM_TYPE: case CL_MEM_FLAGS: case CL_MEM_SIZE: case CL_MEM_MAP_COUNT: case CL_MEM_REFERENCE_COUNT: return UINT2NUM(param_value); case CL_MEM_HOST_PTR: // CHECK: Should be wrapped to a HostPoiner? MappedPointer? No. return ULONG2NUM(param_value); case CL_MEM_CONTEXT: return RContext((cl_context)param_value); default: break; } return Qnil; }
cl_int WINAPI wine_clGetMemObjectInfo(cl_mem memobj, cl_mem_info param_name, size_t param_value_size, void * param_value, size_t * param_value_size_ret) { cl_int ret; TRACE("\n"); ret = clGetMemObjectInfo(memobj, param_name, param_value_size, param_value, param_value_size_ret); return ret; }
bool memory<WorkTypes, ContainerT>::cl_check_buffer_size() { logger->write_info("### Start cl_check buffer size ###",utils::format_type::type_header); platdevices_info *platdevices = get_platdevices_data(); int count_mem_object = 0; int sum_signature = 0; char *signature_input; signature_input;// = new char[platdevices->node_tire_input->size()]; logger->write_info("memory::::cl_check_buffer_size", boost::lexical_cast<std::string>( platdevices->vec_buffer.size())); if(platdevices->vec_buffer.size() == 0) return false; for(int count_vec = 0; count_vec < platdevices->vec_buffer.size(); count_vec ++) { clGetMemObjectInfo(platdevices->vec_buffer[count_vec], CL_MEM_SIZE, sizeof(signature_input) * platdevices->num_devices, signature_input, NULL); sum_signature++; } logger->write_info("--- buffer size ", lexical_cast<std::string>(sum_signature)); return true; }
/** Test if all the objects exist on the same command queue. * @return CL_SUCCESS if all the objects are associated * with the command queue. CL_INVALID_CONTEXT if the objects * are associated to different command queues. Other errors * can be returned if some objects are invalid. */ cl_int testCommandQueue(cl_command_queue command_queue , cl_mem mem , cl_uint num_events_in_wait_list , const ocland_event * event_wait_list) { unsigned int i; cl_int flag; cl_context context, aux_context; flag = clGetCommandQueueInfo(command_queue, CL_QUEUE_CONTEXT, sizeof(cl_context), &context, NULL); if(flag != CL_SUCCESS) return flag; flag = clGetMemObjectInfo(mem, CL_MEM_CONTEXT, sizeof(cl_context), &aux_context, NULL); if(flag != CL_SUCCESS) return flag; if(context != aux_context) return CL_INVALID_CONTEXT; for(i=0;i<num_events_in_wait_list;i++){ if(event_wait_list[i]->context != context) return CL_INVALID_CONTEXT; if(event_wait_list[i]->command_queue){ // Can be NULL if(event_wait_list[i]->command_queue != command_queue) return CL_INVALID_CONTEXT; } } return CL_SUCCESS; }
/* * Validate cl_mem buffers regarding required size including offset; * element_size - size of vector element in bytes, sizeof(T) * count - number of elements, * mem - object to validate * off_mem - offset of first element of vector mem counted in elements */ clsparseStatus validateMemObjectSize(size_t element_size, size_t count, cl_mem mem, size_t off_mem) { #ifndef NDEBUG size_t mem_size; //cl_mem current size size_t vec_size = count * element_size; off_mem *= element_size; //it's a copy if (count == 0) { return clsparseInvalidSize; } cl_int status = clGetMemObjectInfo(mem, CL_MEM_SIZE, sizeof(mem_size), &mem_size, NULL); if (status != CL_SUCCESS) { return clsparseInvalidMemObj; } if ((off_mem + vec_size > mem_size) || (off_mem + vec_size < off_mem)) { return clsparseInsufficientMemory; } #endif return clsparseSuccess; }
void closeScan(ScanPara* SP){ cl_int status; cl_uint refCount; status = clGetMemObjectInfo(SP->tempBuffer, CL_MEM_REFERENCE_COUNT, sizeof(cl_uint), &refCount, NULL); //printf("refCount: %d\n", refCount); while(refCount != 0) { //printf("release tempBuffer\n\n"); CL_FREE(SP->tempBuffer); //reduce count by 1 //printf("success release tempBuffer\n"); refCount--; } for(int i = 0; i < (int)SP->pass; i++) { status = clGetMemObjectInfo(SP->outputBuffer[i], CL_MEM_REFERENCE_COUNT, sizeof(cl_uint), &refCount, NULL); while(refCount != 0) { //printf("release outputBuffer\n\n"); CL_FREE(SP->outputBuffer[i]); //reduce count by 1 refCount--; //printf("success release outputBuffer\n"); } status = clGetMemObjectInfo(SP->blockSumBuffer[i], CL_MEM_REFERENCE_COUNT, sizeof(cl_uint), &refCount, NULL); while(refCount != 0) { //printf("release blockSumBuffer\n\n"); CL_FREE(SP->blockSumBuffer[i]); //reduce count by 1 refCount--; //printf("success release blockSumBuffer\n"); } } //HOST_FREE(SP); }
clblasStatus VISIBILITY_HIDDEN checkVectorSizes( DataType dtype, size_t N, cl_mem x, size_t offx, int incx, ErrorCodeSet err ) { size_t memSize, sizev; size_t tsize; if (N == 0) { return clblasInvalidDim; } if (incx == 0) { switch( err ) { case X_VEC_ERRSET: return clblasInvalidIncX; case Y_VEC_ERRSET: return clblasInvalidIncY; default: return clblasNotImplemented; } } if (clGetMemObjectInfo(x, CL_MEM_SIZE, sizeof(memSize), &memSize, NULL) != CL_SUCCESS) { switch( err ) { case X_VEC_ERRSET: return clblasInvalidVecX; case Y_VEC_ERRSET: return clblasInvalidVecY; default: return clblasNotImplemented; } } tsize = dtypeSize(dtype); sizev = ((N - 1) * abs(incx) + 1) * tsize; offx *= tsize; if ((offx + sizev > memSize) || (offx + sizev < offx)) { switch( err ) { case X_VEC_ERRSET: return clblasInsufficientMemVecX; case Y_VEC_ERRSET: return clblasInsufficientMemVecY; default: return clblasNotImplemented; } } return clblasSuccess; }
/*! Returns the offset of this buffer within its parentBuffer() if it is a sub-buffer; zero otherwise. \sa createSubBuffer(), parentBuffer() */ size_t QCLBuffer::offset() const { size_t value; if (clGetMemObjectInfo(memoryId(), CL_MEM_OFFSET, sizeof(value), &value, 0) != CL_SUCCESS) return 0; else return value; }
/*! Returns the parent of this buffer if it is a sub-buffer; null otherwise. \sa createSubBuffer(), offset() */ QCLBuffer QCLBuffer::parentBuffer() const { cl_mem parent; if (clGetMemObjectInfo(memoryId(), CL_MEM_ASSOCIATED_MEMOBJECT, sizeof(parent), &parent, 0) != CL_SUCCESS) return QCLBuffer(); if (parent) clRetainMemObject(parent); return QCLBuffer(context(), parent); }
struct _cl_version clGetMemObjectVersion(cl_mem memobj) { struct _cl_version version; version.major = 0; version.minor = 0; cl_context context = NULL; cl_int flag = clGetMemObjectInfo(memobj, CL_MEM_CONTEXT, sizeof(cl_context), &context, NULL); if(flag != CL_SUCCESS) return version; return clGetContextVersion(context); }
/** Test if the memory object has enought memory. * @return CL_SUCCESS if memory object has enought * memory allocated, CL_INVALID_VALUE if size * provided is out of bounds, or error if * unavailable data. */ cl_int testSize(cl_mem mem , size_t cb) { cl_int flag; size_t mem_size; flag = clGetMemObjectInfo(mem, CL_MEM_SIZE, sizeof(size_t), &mem_size, NULL); if(flag != CL_SUCCESS) return flag; if(mem_size < cb) return CL_INVALID_VALUE; return CL_SUCCESS; }
cl_uint CL_Image3D::GetReferenceCount() const { CL_CPP_CONDITIONAL_RETURN_VALUE(!m_Image, 0); // Dynamically retrieve the current reference count for this kernel. cl_uint uRefCount = 0; cl_int iErrorCode = clGetMemObjectInfo(m_Image, CL_MEM_REFERENCE_COUNT, sizeof(cl_uint), &uRefCount, NULL); CL_CPP_CATCH_ERROR(iErrorCode); return uRefCount; }
/** Test if the memory object is writable. * @return CL_SUCCESS if memory object can * be written, CL_INVALID_OPERATION if is * not accessable object, or error if * unavailable data. */ cl_int testWriteable(cl_mem mem) { cl_int flag; cl_mem_flags flags; flag = clGetMemObjectInfo(mem, CL_MEM_FLAGS, sizeof(cl_mem_flags), &flags, NULL); if(flag != CL_SUCCESS) return flag; if( (flags & CL_MEM_HOST_READ_ONLY) || (flags & CL_MEM_HOST_NO_ACCESS)) return CL_INVALID_OPERATION; return CL_SUCCESS; }
void clwUnmapOutputOrPartDer(cl_mem p_buffer) { clwInitLib(); void* ptr; cl_int res = clGetMemObjectInfo(p_buffer, CL_MEM_HOST_PTR, sizeof(void*), &ptr, NULL); if (res != CL_SUCCESS) { std::cerr<<"UnmapOutputOrPartDer: "<<res<<std::endl; getchar(); } res = clEnqueueUnmapMemObject(g_cl_Command_Queue, p_buffer, ptr, 0, nullptr, nullptr); if (res != CL_SUCCESS) { std::cerr<<"UnmapOutputOrPartDer: "<<res<<std::endl; getchar(); } #ifdef FINISH res = clFinish(g_cl_Command_Queue); #else res = clEnqueueBarrierWithWaitList(g_cl_Command_Queue, 0, nullptr, nullptr); #endif if (res != CL_SUCCESS) { std::cerr<<"UnmapOutputOrPartDer: "<<res<<std::endl; getchar(); } }
/* Split kernel utility functions. */ size_t get_tex_size(const char *tex_name) { cl_mem ptr; size_t ret_size = 0; MemMap::iterator i = mem_map.find(tex_name); if(i != mem_map.end()) { ptr = CL_MEM_PTR(i->second); ciErr = clGetMemObjectInfo(ptr, CL_MEM_SIZE, sizeof(ret_size), &ret_size, NULL); assert(ciErr == CL_SUCCESS); } return ret_size; }
WEAK bool halide_validate_dev_pointer(buffer_t* buf, size_t size=0) { if (buf->dev == 0) return true; size_t real_size; cl_int result = clGetMemObjectInfo((cl_mem)buf->dev, CL_MEM_SIZE, sizeof(size_t), &real_size, NULL); if (result) { halide_printf("Bad device pointer %p: clGetMemObjectInfo returned %d\n", (void *)buf->dev, result); return false; } #ifdef DEBUG halide_printf("validate %p: asked for %lld, actual allocated %lld\n", (void*)buf->dev, (long long)size, (long long)real_size); #endif if (size) halide_assert(real_size >= size && "Validating pointer with insufficient size"); return true; }
bool CLMemory::get_cl_mem_info ( cl_image_info param_name, size_t param_size, void *param, size_t *param_size_ret) { cl_mem mem_id = get_mem_id (); cl_int error_code = CL_SUCCESS; if (!mem_id) return false; error_code = clGetMemObjectInfo (mem_id, param_name, param_size, param, param_size_ret); XCAM_FAIL_RETURN( WARNING, error_code == CL_SUCCESS, false, "clGetMemObjectInfo failed on param:%d, errno:%d", param_name, error_code); return true; }
size_t cl_mem_size(const cl_mem& mem) { size_t mem_size, bytes_written; cl_int err; err = clGetMemObjectInfo(mem, CL_MEM_SIZE, sizeof(size_t), &mem_size, &bytes_written); if (error_cl(err, "clGetMemObjectInfo CL_MEM_SIZE")) return -1; return mem_size; }
cl_mem mitk::OclDataSet::GetGPUBuffer() { // query image object info only if already initialized if( this->m_gpuBuffer ) { #ifdef SHOW_MEM_INFO cl_int clErr = 0; // clGetMemObjectInfo() cl_mem_object_type memInfo; clErr = clGetMemObjectInfo(this->m_gpuBuffer, CL_MEM_TYPE, sizeof(cl_mem_object_type), &memInfo, nullptr ); CHECK_OCL_ERR(clErr); MITK_DEBUG << "Querying info for object, recieving: " << memInfo; #endif } return m_gpuBuffer; }
/* Calculates the texture memories and KernelData (d_data) memory * that has been allocated. */ size_t get_scene_specific_mem_allocated(cl_mem d_data) { size_t scene_specific_mem_allocated = 0; /* Calculate texture memories. */ #define KERNEL_TEX(type, ttype, name) \ scene_specific_mem_allocated += get_tex_size(#name); #include "kernel_textures.h" #undef KERNEL_TEX size_t d_data_size; ciErr = clGetMemObjectInfo(d_data, CL_MEM_SIZE, sizeof(d_data_size), &d_data_size, NULL); assert(ciErr == CL_SUCCESS && "Can't get d_data mem object info"); scene_specific_mem_allocated += d_data_size; return scene_specific_mem_allocated; }
mem::~mem() { if (mem_ == NULL) return; cl_uint reference_count = 0; clGetMemObjectInfo(mem_, CL_MEM_REFERENCE_COUNT, sizeof(cl_uint), &reference_count, 0); for (cl_uint i = 0; i < reference_count; ++i) { clReleaseMemObject(mem_); } mem_ = NULL; valid_ = false; }
WEAK bool halide_validate_dev_pointer(void *user_context, buffer_t* buf, size_t size=0) { if (buf->dev == 0) { return true; } size_t real_size; cl_int result = clGetMemObjectInfo((cl_mem)buf->dev, CL_MEM_SIZE, sizeof(size_t), &real_size, NULL); if (result != CL_SUCCESS) { halide_printf(user_context, "CL: Bad device pointer %p: clGetMemObjectInfo returned %d\n", (void *)buf->dev, result); return false; } DEBUG_PRINTF( user_context, "CL: validate %p: asked for %lld, actual allocated %lld\n", (void*)buf->dev, (long long)size, (long long)real_size ); if (size) halide_assert(user_context, real_size >= size && "Validating pointer with insufficient size"); return true; }
//----------------------------------------------------------------------------- // Name: InitTextures() // Desc: Initializes Direct3D Textures (allocation and initialization) //----------------------------------------------------------------------------- HRESULT InitTextures() { // // create the D3D resources we'll be using // // 2D texture g_texture_2d.width = 256; g_texture_2d.height = 256; g_texture_2d.pitch = 256; if (FAILED(g_pD3DDevice->CreateTexture(g_texture_2d.width, g_texture_2d.height, 1, D3DUSAGE_DYNAMIC, D3DFMT_A8R8G8B8/*D3DFMT_A32B32G32R32F*/, D3DPOOL_DEFAULT, &g_texture_2d.pTexture, NULL) )) { return E_FAIL; } D3DLOCKED_RECT r; HRESULT hr = g_texture_2d.pTexture->LockRect(0, &r, NULL, 0); unsigned long *data = (unsigned long *)r.pBits; for(int i=0; i< 256*256; i++) { *data = 0xFF00FFFF; data++; } g_texture_2d.pTexture->UnlockRect(0); // Create the OpenCL part g_texture_2d.clTexture = clCreateFromD3D9TextureNV( cxGPUContext, 0, g_texture_2d.pTexture, 0,//miplevel &ciErrNum); oclCheckErrorEX(ciErrNum, CL_SUCCESS, pCleanup); // // Optional Check... // IDirect3DResource9* clResource = NULL; ciErrNum = clGetMemObjectInfo( g_texture_2d.clTexture, CL_MEM_D3D9_RESOURCE_NV, sizeof(clResource), &clResource, NULL); assert(clResource == g_texture_2d.pTexture); #ifdef USE_STAGING_BUFFER // Memory Setup : allocate 4 bytes (RGBA) pixels // Create the intermediate buffers in which OpenCL will do the rendering // then we will blit the result back to the texture that we will have mapped to OpenCL area g_texture_2d.clMem = clCreateBuffer(cxGPUContext, CL_MEM_READ_ONLY, 4 * g_texture_2d.width * g_texture_2d.height, NULL, &ciErrNum); oclCheckErrorEX(ciErrNum, CL_SUCCESS, pCleanup); #endif // cube texture g_texture_cube.size = 64; g_texture_cube.pitch = 64; if (FAILED(g_pD3DDevice->CreateCubeTexture(g_texture_cube.size, 1, D3DUSAGE_DYNAMIC, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &g_texture_cube.pTexture, NULL) )) { return E_FAIL; } // Create the OpenCL part for(int i=0; i<6; i++) { g_texture_cube.clTexture[i] = clCreateFromD3D9CubeTextureNV( cxGPUContext, 0, g_texture_cube.pTexture, (D3DCUBEMAP_FACES)i, // face 0, // miplevel &ciErrNum); oclCheckErrorEX(ciErrNum, CL_SUCCESS, pCleanup); #ifdef USE_STAGING_BUFFER g_texture_cube.clMem[i] = clCreateBuffer(cxGPUContext, CL_MEM_READ_ONLY, 4 * g_texture_cube.size * g_texture_cube.size, NULL, &ciErrNum); oclCheckErrorEX(ciErrNum, CL_SUCCESS, pCleanup); #endif } // 3D texture g_texture_vol.width = 16; g_texture_vol.height = 16; g_texture_vol.depth = 8; g_texture_vol.pitch = 16; g_texture_vol.pitchslice = g_texture_vol.pitch * g_texture_vol.height; if (FAILED(g_pD3DDevice->CreateVolumeTexture( g_texture_vol.width, g_texture_vol.height, g_texture_vol.depth, 1, D3DUSAGE_DYNAMIC, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &g_texture_vol.pTexture, NULL) )) { return E_FAIL; } g_texture_vol.clTexture = clCreateFromD3D9VolumeTextureNV( cxGPUContext, 0, g_texture_vol.pTexture, 0, //Miplevel &ciErrNum); oclCheckErrorEX(ciErrNum, CL_SUCCESS, pCleanup); g_texture_vol.clMem = clCreateBuffer(cxGPUContext, CL_MEM_READ_ONLY, 4 * g_texture_vol.width * g_texture_vol.height * g_texture_vol.depth, NULL, &ciErrNum); oclCheckErrorEX(ciErrNum, CL_SUCCESS, pCleanup); return S_OK; }
clblasStatus checkMemObjects( cl_mem A, cl_mem B, cl_mem C, bool checkC, ErrorCodeSet errA, ErrorCodeSet errB, ErrorCodeSet errC ) { cl_mem_object_type mobjType = 0; if (!clGetMemObjectInfo(A, CL_MEM_TYPE, sizeof(mobjType), &mobjType, NULL) && (mobjType != CL_MEM_OBJECT_BUFFER)) { switch( errA ) { case A_MAT_ERRSET: return clblasInvalidMatA; case B_MAT_ERRSET: return clblasInvalidMatB; case C_MAT_ERRSET: return clblasInvalidMatC; case X_VEC_ERRSET: return clblasInvalidVecX; case Y_VEC_ERRSET: return clblasInvalidVecY; default: return clblasNotImplemented; } } mobjType = 0; if (!clGetMemObjectInfo(B, CL_MEM_TYPE, sizeof(mobjType), &mobjType, NULL) && (mobjType != CL_MEM_OBJECT_BUFFER)) { switch( errB ) { case A_MAT_ERRSET: return clblasInvalidMatA; case B_MAT_ERRSET: return clblasInvalidMatB; case C_MAT_ERRSET: return clblasInvalidMatC; case X_VEC_ERRSET: return clblasInvalidVecX; case Y_VEC_ERRSET: return clblasInvalidVecY; default: return clblasNotImplemented; } } mobjType = 0; if (checkC && !clGetMemObjectInfo(C, CL_MEM_TYPE, sizeof(mobjType), &mobjType, NULL) && (mobjType != CL_MEM_OBJECT_BUFFER)) { switch( errC ) { case A_MAT_ERRSET: return clblasInvalidMatA; case B_MAT_ERRSET: return clblasInvalidMatB; case C_MAT_ERRSET: return clblasInvalidMatC; case X_VEC_ERRSET: return clblasInvalidVecX; case Y_VEC_ERRSET: return clblasInvalidVecY; default: return clblasNotImplemented; } } return clblasSuccess; }
clblasStatus VISIBILITY_HIDDEN checkBandedMatrixSizes( DataType dtype, clblasOrder order, clblasTranspose transA, size_t M, size_t N, size_t KL, size_t KU, cl_mem A, size_t offA, size_t lda, ErrorCodeSet err ) { size_t memSize, matrSize, tsize, K, memUsed; size_t unusedTail = 0; bool tra; if ((M == 0) || (N == 0)) { return clblasInvalidDim; } tsize = dtypeSize(dtype); K = KL + KU + 1; tra = (order == clblasRowMajor && transA != clblasNoTrans) || (order == clblasColumnMajor && transA == clblasNoTrans); if (lda < K) { switch( err ) { case A_MAT_ERRSET: return clblasInvalidLeadDimA; case B_MAT_ERRSET: return clblasInvalidLeadDimB; case C_MAT_ERRSET: return clblasInvalidLeadDimC; default: return clblasNotImplemented; } } if (tra) { matrSize = ((N - 1) * lda + K) * tsize; unusedTail = ( lda - N ) * tsize; } else { matrSize = ((M - 1) * lda + K) * tsize; unusedTail = ( lda - M ) * tsize; } offA *= tsize; if (clGetMemObjectInfo(A, CL_MEM_SIZE, sizeof(memSize), &memSize, NULL) != CL_SUCCESS) { switch( err ) { case A_MAT_ERRSET: return clblasInvalidMatA; case B_MAT_ERRSET: return clblasInvalidMatB; case C_MAT_ERRSET: return clblasInvalidMatC; default: return clblasNotImplemented; } } // Calculates the memory required. Note that 'matrSize' already takes into account the fact that // there might be an unused tail, i.e. the elements between lda and M in the last column if // column major is used or between lda and N in the last row if row major is used. memUsed = offA + matrSize; if (memUsed > memSize) { switch( err ) { case A_MAT_ERRSET: return clblasInsufficientMemMatA; case B_MAT_ERRSET: return clblasInsufficientMemMatB; case C_MAT_ERRSET: return clblasInsufficientMemMatC; default: return clblasNotImplemented; } } return clblasSuccess; }