MemoryRegion::MemoryRegion(bool fine_grain, const core::Agent& owner,
                           const HsaMemoryProperties& mem_props)
    : core::MemoryRegion(fine_grain),
      owner_(&owner),
      mem_props_(mem_props),
      max_single_alloc_size_(0),
      virtual_size_(0) {
    virtual_size_ = GetPhysicalSize();

    mem_flag_.Value = 0;
    if (IsLocalMemory()) {
        mem_flag_.ui32.PageSize = HSA_PAGE_SIZE_4KB;
        mem_flag_.ui32.NoSubstitute = 1;
        mem_flag_.ui32.HostAccess = 0;
        mem_flag_.ui32.NonPaged = 1;

        char* char_end = NULL;
        HSAuint64 max_alloc_size = static_cast<HSAuint64>(strtoull(
                                       os::GetEnvVar("HSA_LOCAL_MEMORY_MAX_ALLOC").c_str(), &char_end, 10));
        max_alloc_size = std::max(max_alloc_size, GetPhysicalSize() / 4);
        max_alloc_size = std::min(max_alloc_size, GetPhysicalSize());

        max_single_alloc_size_ =
            AlignDown(static_cast<size_t>(max_alloc_size), kPageSize_);

        static const HSAuint64 kGpuVmSize = (1ULL << 40);
        virtual_size_ = kGpuVmSize;
    } else if (IsSystem()) {
        mem_flag_.ui32.PageSize = HSA_PAGE_SIZE_4KB;
        mem_flag_.ui32.NoSubstitute = 1;
        mem_flag_.ui32.HostAccess = 1;
        mem_flag_.ui32.CachePolicy = HSA_CACHING_CACHED;

        max_single_alloc_size_ =
            AlignDown(static_cast<size_t>(GetPhysicalSize()), kPageSize_);

        virtual_size_ = os::GetUserModeVirtualMemorySize();
    }

    assert(GetVirtualSize() != 0);
    assert(GetPhysicalSize() <= GetVirtualSize());
    assert(IsMultipleOf(max_single_alloc_size_, kPageSize_));
}
Example #2
0
Size RichObjectType::StdDefaultSize(const Value& data, Size maxsize, void * context) const
{
	if(IsNull(data)) return Size(0, 0);
	Size psz = GetPhysicalSize(data, context);
	if((psz.cx | psz.cy) == 0)
		psz = 625 * GetPixelSize(data, context) / 100;
	Size sz;
	for(int i = 1; i < 10000; i++) {
		sz = psz / i;
		if(sz.cx <= maxsize.cx && sz.cy <= maxsize.cy)
			break;
	}
	return sz;
}
Example #3
0
QVariantMap UIDirect3D9Window::GetDisplayDetails(void)
{
    QVariantMap result;
    QSize mm = GetPhysicalSize();
    QSize pixels = GetSize();

    result.insert("refreshrate", GetRefreshRate());
    result.insert("widthmm", mm.width());
    result.insert("heightmm", mm.height());
    result.insert("aspectratio", (float)mm.width() / (float)mm.height());
    result.insert("widthpixels", pixels.width());
    result.insert("heightpixels", pixels.height());
    result.insert("renderer", "Direct3D9");
    result.insert("studiolevels", m_studioLevels);
    return result;
}
Example #4
0
Size RichObjectType::GetPhysicalSize(const Value& data, void *context) const
{
	return GetPhysicalSize(data);
}
hsa_status_t MemoryRegion::GetInfo(hsa_region_info_t attribute,
                                   void* value) const {
    switch (attribute) {
    case HSA_REGION_INFO_SEGMENT:
        switch (mem_props_.HeapType) {
        case HSA_HEAPTYPE_SYSTEM:
        case HSA_HEAPTYPE_FRAME_BUFFER_PRIVATE:
        case HSA_HEAPTYPE_FRAME_BUFFER_PUBLIC:
            *((hsa_region_segment_t*)value) = HSA_REGION_SEGMENT_GLOBAL;
            break;
        case HSA_HEAPTYPE_GPU_LDS:
            *((hsa_region_segment_t*)value) = HSA_REGION_SEGMENT_GROUP;
            break;
        default:
            assert(false && "Memory region should only be global, group");
            break;
        }
        break;
    case HSA_REGION_INFO_GLOBAL_FLAGS:
        switch (mem_props_.HeapType) {
        case HSA_HEAPTYPE_SYSTEM:
            *((uint32_t*)value) = (HSA_REGION_GLOBAL_FLAG_KERNARG |
                                   HSA_REGION_GLOBAL_FLAG_FINE_GRAINED);
            break;
        case HSA_HEAPTYPE_FRAME_BUFFER_PRIVATE:
        case HSA_HEAPTYPE_FRAME_BUFFER_PUBLIC:
            *((uint32_t*)value) = HSA_REGION_GLOBAL_FLAG_COARSE_GRAINED;
            break;
        default:
            *((uint32_t*)value) = 0;
            break;
        }
        break;
    case HSA_REGION_INFO_SIZE:
        switch (mem_props_.HeapType) {
        case HSA_HEAPTYPE_FRAME_BUFFER_PRIVATE:
        case HSA_HEAPTYPE_FRAME_BUFFER_PUBLIC:
            // TODO: report the actual physical size of local memory until API to
            // explicitly unpin memory is available.
            *((size_t*)value) = static_cast<size_t>(GetPhysicalSize());
            break;
        default:
            *((size_t*)value) = static_cast<size_t>(GetVirtualSize());
            break;
        }
        break;
    case HSA_REGION_INFO_ALLOC_MAX_SIZE:
        switch (mem_props_.HeapType) {
        case HSA_HEAPTYPE_FRAME_BUFFER_PRIVATE:
        case HSA_HEAPTYPE_FRAME_BUFFER_PUBLIC:
        case HSA_HEAPTYPE_SYSTEM:
            *((size_t*)value) = max_single_alloc_size_;
            break;
        default:
            *((size_t*)value) = 0;
        }
        break;
    case HSA_REGION_INFO_RUNTIME_ALLOC_ALLOWED:
        switch (mem_props_.HeapType) {
        case HSA_HEAPTYPE_SYSTEM:
        case HSA_HEAPTYPE_FRAME_BUFFER_PRIVATE:
        case HSA_HEAPTYPE_FRAME_BUFFER_PUBLIC:
            *((bool*)value) = true;
            break;
        default:
            *((bool*)value) = false;
            break;
        }
        break;
    case HSA_REGION_INFO_RUNTIME_ALLOC_GRANULE:
        // TODO: remove the hardcoded value.
        switch (mem_props_.HeapType) {
        case HSA_HEAPTYPE_SYSTEM:
        case HSA_HEAPTYPE_FRAME_BUFFER_PRIVATE:
        case HSA_HEAPTYPE_FRAME_BUFFER_PUBLIC:
            *((size_t*)value) = kPageSize_;
            break;
        default:
            *((size_t*)value) = 0;
            break;
        }
        break;
    case HSA_REGION_INFO_RUNTIME_ALLOC_ALIGNMENT:
        // TODO: remove the hardcoded value.
        switch (mem_props_.HeapType) {
        case HSA_HEAPTYPE_SYSTEM:
        case HSA_HEAPTYPE_FRAME_BUFFER_PRIVATE:
        case HSA_HEAPTYPE_FRAME_BUFFER_PUBLIC:
            *((size_t*)value) = kPageSize_;
            break;
        default:
            *((size_t*)value) = 0;
            break;
        }
        break;
    default:
        switch ((hsa_amd_region_info_t)attribute) {
        case HSA_AMD_REGION_INFO_HOST_ACCESSIBLE:
            *((bool*)value) =
                (mem_props_.HeapType == HSA_HEAPTYPE_SYSTEM) ? true : false;
            break;
        case HSA_AMD_REGION_INFO_BASE:
            *((void**)value) = reinterpret_cast<void*>(GetBaseAddress());
            break;
        default:
            return HSA_STATUS_ERROR_INVALID_ARGUMENT;
            break;
        }
        break;
    }
    return HSA_STATUS_SUCCESS;
}