def test_externals_setitem(): dhf = ProxifyHostFile(device_memory_limit=one_item_nbytes) k1 = dhf.add_external(one_item_array()) assert type(k1) is dask_cuda.proxy_object.ProxyObject assert len(dhf) == 0 assert "external" in k1._obj_pxy assert "external_finalize" in k1._obj_pxy dhf["k1"] = k1 k1 = dhf["k1"] assert type(k1) is dask_cuda.proxy_object.ProxyObject assert len(dhf) == 1 assert "external" not in k1._obj_pxy assert "external_finalize" not in k1._obj_pxy k1 = dhf.add_external(one_item_array()) k1._obj_pxy_serialize(serializers=("dask", "pickle")) dhf["k1"] = k1 k1 = dhf["k1"] assert type(k1) is dask_cuda.proxy_object.ProxyObject assert len(dhf) == 1 assert "external" not in k1._obj_pxy assert "external_finalize" not in k1._obj_pxy dhf["k1"] = one_item_array() assert len(dhf.proxies_tally.proxy_id_to_proxy) == 1 assert dhf.proxies_tally.get_dev_mem_usage() == one_item_nbytes k1 = dhf.add_external(k1) assert len(dhf.proxies_tally.proxy_id_to_proxy) == 1 assert dhf.proxies_tally.get_dev_mem_usage() == one_item_nbytes k1 = dhf.add_external(dhf["k1"]) assert len(dhf.proxies_tally.proxy_id_to_proxy) == 1 assert dhf.proxies_tally.get_dev_mem_usage() == one_item_nbytes
def test_externals(): dhf = ProxifyHostFile(device_memory_limit=one_item_nbytes) dhf["k1"] = one_item_array() k1 = dhf["k1"] k2 = dhf.add_external(one_item_array()) # `k2` isn't part of the store but still triggers spilling of `k1` assert len(dhf) == 1 assert k1._obj_pxy_is_serialized() assert not k2._obj_pxy_is_serialized() k1[0] # Trigger spilling of `k2` assert not k1._obj_pxy_is_serialized() assert k2._obj_pxy_is_serialized() k2[0] # Trigger spilling of `k1` assert k1._obj_pxy_is_serialized() assert not k2._obj_pxy_is_serialized() assert dhf.proxies_tally.get_dev_mem_usage() == one_item_nbytes # Removing `k2` also removes it from the tally del k2 assert dhf.proxies_tally.get_dev_mem_usage() == 0 assert len(list(dhf.proxies_tally.get_unspilled_proxies())) == 0