Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/device/hip/device_impl.cpp
| Show First 20 Lines • Show All 87 Lines • ▼ Show 20 Lines | HIPDevice::HIPDevice(const DeviceInfo &info, Stats &stats, Profiler &profiler) | ||||
| /* Initialize HIP. */ | /* Initialize HIP. */ | ||||
| hipError_t result = hipInit(0); | hipError_t result = hipInit(0); | ||||
| if (result != hipSuccess) { | if (result != hipSuccess) { | ||||
| set_error(string_printf("Failed to initialize HIP runtime (%s)", hipewErrorString(result))); | set_error(string_printf("Failed to initialize HIP runtime (%s)", hipewErrorString(result))); | ||||
| return; | return; | ||||
| } | } | ||||
| /* Setup device and context. */ | /* Setup device and context. */ | ||||
| result = hipGetDevice(&hipDevice, hipDevId); | result = hipDeviceGet(&hipDevice, hipDevId); | ||||
| if (result != hipSuccess) { | if (result != hipSuccess) { | ||||
| set_error(string_printf("Failed to get HIP device handle from ordinal (%s)", | set_error(string_printf("Failed to get HIP device handle from ordinal (%s)", | ||||
| hipewErrorString(result))); | hipewErrorString(result))); | ||||
| return; | return; | ||||
| } | } | ||||
| /* hipDeviceMapHost for mapping host memory when out of device memory. | /* hipDeviceMapHost for mapping host memory when out of device memory. | ||||
| * hipDeviceLmemResizeToMax for reserving local memory ahead of render, | * hipDeviceLmemResizeToMax for reserving local memory ahead of render, | ||||
| ▲ Show 20 Lines • Show All 628 Lines • ▼ Show 20 Lines | void HIPDevice::generic_copy_to(device_memory &mem) | ||||
| } | } | ||||
| } | } | ||||
| void HIPDevice::generic_free(device_memory &mem) | void HIPDevice::generic_free(device_memory &mem) | ||||
| { | { | ||||
| if (mem.device_pointer) { | if (mem.device_pointer) { | ||||
| HIPContextScope scope(this); | HIPContextScope scope(this); | ||||
| thread_scoped_lock lock(hip_mem_map_mutex); | thread_scoped_lock lock(hip_mem_map_mutex); | ||||
| DCHECK(hip_mem_map.find(&mem) != hip_mem_map.end()); | |||||
| const HIPMem &cmem = hip_mem_map[&mem]; | const HIPMem &cmem = hip_mem_map[&mem]; | ||||
| /* If cmem.use_mapped_host is true, reference counting is used | /* If cmem.use_mapped_host is true, reference counting is used | ||||
| * to safely free a mapped host memory. */ | * to safely free a mapped host memory. */ | ||||
| if (cmem.use_mapped_host) { | if (cmem.use_mapped_host) { | ||||
| assert(mem.shared_pointer); | assert(mem.shared_pointer); | ||||
| if (mem.shared_pointer) { | if (mem.shared_pointer) { | ||||
| ▲ Show 20 Lines • Show All 226 Lines • ▼ Show 20 Lines | else if (mem.data_depth > 1) { | ||||
| desc.Format = format; | desc.Format = format; | ||||
| desc.NumChannels = mem.data_elements; | desc.NumChannels = mem.data_elements; | ||||
| desc.Flags = 0; | desc.Flags = 0; | ||||
| VLOG(1) << "Array 3D allocate: " << mem.name << ", " | VLOG(1) << "Array 3D allocate: " << mem.name << ", " | ||||
| << string_human_readable_number(mem.memory_size()) << " bytes. (" | << string_human_readable_number(mem.memory_size()) << " bytes. (" | ||||
| << string_human_readable_size(mem.memory_size()) << ")"; | << string_human_readable_size(mem.memory_size()) << ")"; | ||||
| hip_assert(hipArray3DCreate(&array_3d, &desc)); | hip_assert(hipArray3DCreate((hArray *)&array_3d, &desc)); | ||||
| if (!array_3d) { | if (!array_3d) { | ||||
| return; | return; | ||||
| } | } | ||||
| HIP_MEMCPY3D param; | HIP_MEMCPY3D param; | ||||
| memset(¶m, 0, sizeof(param)); | memset(¶m, 0, sizeof(HIP_MEMCPY3D)); | ||||
| param.dstMemoryType = hipMemoryTypeArray; | param.dstMemoryType = hipMemoryTypeArray; | ||||
| param.dstArray = &array_3d; | param.dstArray = array_3d; | ||||
| param.srcMemoryType = hipMemoryTypeHost; | param.srcMemoryType = hipMemoryTypeHost; | ||||
| param.srcHost = mem.host_pointer; | param.srcHost = mem.host_pointer; | ||||
| param.srcPitch = src_pitch; | param.srcPitch = src_pitch; | ||||
| param.WidthInBytes = param.srcPitch; | param.WidthInBytes = param.srcPitch; | ||||
| param.Height = mem.data_height; | param.Height = mem.data_height; | ||||
| param.Depth = mem.data_depth; | param.Depth = mem.data_depth; | ||||
| hip_assert(hipDrvMemcpy3D(¶m)); | hip_assert(hipDrvMemcpy3D(¶m)); | ||||
| ▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | void HIPDevice::tex_alloc(device_texture &mem) | ||||
| } | } | ||||
| /* Set Mapping and tag that we need to (re-)upload to device */ | /* Set Mapping and tag that we need to (re-)upload to device */ | ||||
| texture_info[slot] = mem.info; | texture_info[slot] = mem.info; | ||||
| need_texture_info = true; | need_texture_info = true; | ||||
| if (mem.info.data_type != IMAGE_DATA_TYPE_NANOVDB_FLOAT && | if (mem.info.data_type != IMAGE_DATA_TYPE_NANOVDB_FLOAT && | ||||
| mem.info.data_type != IMAGE_DATA_TYPE_NANOVDB_FLOAT3) { | mem.info.data_type != IMAGE_DATA_TYPE_NANOVDB_FLOAT3) { | ||||
| /* Bindless textures. */ | |||||
| hipResourceDesc resDesc; | hipResourceDesc resDesc; | ||||
| memset(&resDesc, 0, sizeof(resDesc)); | memset(&resDesc, 0, sizeof(resDesc)); | ||||
| if (array_3d) { | if (array_3d) { | ||||
| resDesc.resType = hipResourceTypeArray; | resDesc.resType = hipResourceTypeArray; | ||||
| resDesc.res.array.h_Array = &array_3d; | resDesc.res.array.h_Array = array_3d; | ||||
| resDesc.flags = 0; | resDesc.flags = 0; | ||||
| } | } | ||||
| else if (mem.data_height > 0) { | else if (mem.data_height > 0) { | ||||
| resDesc.resType = hipResourceTypePitch2D; | resDesc.resType = hipResourceTypePitch2D; | ||||
| resDesc.res.pitch2D.devPtr = mem.device_pointer; | resDesc.res.pitch2D.devPtr = mem.device_pointer; | ||||
| resDesc.res.pitch2D.format = format; | resDesc.res.pitch2D.format = format; | ||||
| resDesc.res.pitch2D.numChannels = mem.data_elements; | resDesc.res.pitch2D.numChannels = mem.data_elements; | ||||
| resDesc.res.pitch2D.height = mem.data_height; | resDesc.res.pitch2D.height = mem.data_height; | ||||
| Show All 28 Lines | void HIPDevice::tex_alloc(device_texture &mem) | ||||
| } | } | ||||
| } | } | ||||
| void HIPDevice::tex_free(device_texture &mem) | void HIPDevice::tex_free(device_texture &mem) | ||||
| { | { | ||||
| if (mem.device_pointer) { | if (mem.device_pointer) { | ||||
| HIPContextScope scope(this); | HIPContextScope scope(this); | ||||
| thread_scoped_lock lock(hip_mem_map_mutex); | thread_scoped_lock lock(hip_mem_map_mutex); | ||||
| DCHECK(hip_mem_map.find(&mem) != hip_mem_map.end()); | |||||
| const HIPMem &cmem = hip_mem_map[&mem]; | const HIPMem &cmem = hip_mem_map[&mem]; | ||||
| if (cmem.texobject) { | if (cmem.texobject) { | ||||
| /* Free bindless texture. */ | /* Free bindless texture. */ | ||||
| hipTexObjectDestroy(cmem.texobject); | hipTexObjectDestroy(cmem.texobject); | ||||
| } | } | ||||
| if (!mem.is_resident(this)) { | if (!mem.is_resident(this)) { | ||||
| ▲ Show 20 Lines • Show All 86 Lines • Show Last 20 Lines | |||||