def set_max_device_memory(self, max_device_memory): if not Validator.check_str_by_regular(max_device_memory, _re_pattern): raise ValueError("Context param max_device_memory should be in correct format! Such as \"3.5GB\"") max_device_memory_value = float(max_device_memory[:-2]) if max_device_memory_value == 0: raise ValueError("Context param max_device_memory should be in correct format! Such as \"3.5GB\"") self.set_param(ms_ctx_param.max_device_memory, max_device_memory_value)
def set_variable_memory_max_size(self, variable_memory_max_size): """set values of variable_memory_max_size and graph_memory_max_size""" if not Validator.check_str_by_regular(variable_memory_max_size, _re_pattern): raise ValueError("Context param variable_memory_max_size should be in correct format! Such as \"5GB\"") if int(variable_memory_max_size[:-2]) > _DEVICE_APP_MEMORY_SIZE: raise ValueError("Context param variable_memory_max_size should be not greater than 31GB.") variable_memory_max_size_ = variable_memory_max_size[:-2] + " * 1024 * 1024 * 1024" graph_memory_max_size = _DEVICE_APP_MEMORY_SIZE - int(variable_memory_max_size[:-2]) graph_memory_max_size_ = str(graph_memory_max_size) + " * 1024 * 1024 * 1024" self.set_param(ms_ctx_param.variable_memory_max_size, variable_memory_max_size_) self.set_param(ms_ctx_param._graph_memory_max_size, graph_memory_max_size_)
def test_check_str_by_regular(): str1 = "12_sf.asdf_" str2 = "x12_sf.asdf." str3 = "_x12_sf.asdf" str4 = ".12_sf.asdf" str5 = "12_sf.a$sdf." str6 = "12+sf.asdf" Validator.check_str_by_regular(str1) Validator.check_str_by_regular(str2) Validator.check_str_by_regular(str3) with pytest.raises(ValueError): Validator.check_str_by_regular(str4) with pytest.raises(ValueError): Validator.check_str_by_regular(str5) with pytest.raises(ValueError): Validator.check_str_by_regular(str6)