How to enable synchronization 2 when using Vulkan API 1.2? - vulkan

Up until now, I used the the latest Vulkan API available on my development machine (1.3.201).
VK_CHECK(vkEnumerateInstanceVersion(&_apiVersion)); // returns 1.3.201
After some struggles I managed to use synchronization 2 as a core feature (functions without KHR).
But now, I wish to work with API version 1.2 to be compatible with more devices.
So when initializing VkApplicationInfo I set a lower version to the apiVersion field:
appInfo.apiVersion = VK_MAKE_API_VERSION(0, 1, 2, 0);
In order to use synchronization 2 extension, I pass the following extensions & layers to vkCreateInstance:
Extensions:
VK_KHR_surface
VK_KHR_win32_surface
VK_KHR_get_physical_device_properties2
VK_KHR_get_surface_capabilities2
VK_EXT_debug_utils
Layers:
VK_LAYER_KHRONOS_synchronization2
VK_LAYER_KHRONOS_validation
And these are the extensions and layers I pass to vkCreateDevice:
VK_KHR_create_renderpass2
VK_KHR_synchronization2
VK_KHR_swapchain
Layers:
VK_LAYER_KHRONOS_validation
This is my device Initialization code:
VkPhysicalDeviceFeatures deviceFeatures{ };
VkPhysicalDeviceVulkan12Features features12{};
features12.sType = VkStructureType::VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES;
features12.timelineSemaphore = true;
VkDeviceCreateInfo deviceCreateInfo
{
.sType = VkStructureType::VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO,
.pNext = &features12,
.flags = VkDeviceCreateFlags{},
.queueCreateInfoCount = static_cast<uint32_t>(createDesc.queu_create_info.size()),
.pQueueCreateInfos = createDesc.queu_create_info.data(),
.enabledLayerCount = static_cast<uint32_t>(config.required_layers.size()),
.ppEnabledLayerNames = config.required_layers.data(),
.enabledExtensionCount = static_cast<uint32_t>(config.required_extentions.size()),
.ppEnabledExtensionNames = config.required_extentions.data(),
.pEnabledFeatures = &deviceFeatures
};
Yet, when calling vkCmdPipelineBarrier2KHR I get a validation error:
Validation Error: [ VUID-vkCmdPipelineBarrier2-synchronization2-03848 ] Object 0: handle = 0x20b77c136f0, type = VK_OBJECT_TYPE_COMMAND_BUFFER; | MessageID = 0xa060404 | vkCmdPipelineBarrier2KHR(): Synchronization2 feature is not enabled The Vulkan spec states: The synchronization2 feature must be enabled (https://vulkan.lunarg.com/doc/view/1.3.236.0/windows/1.3-extensions/vkspec.html#VUID-vkCmdPipelineBarrier2-synchronization2-03848)

Related

How to switch between policies in multiagent rllib?

For my thesis, I want to train a PPO model on a collaborative multi-agent situation. The 'teammates' are already trained Behavior Cloning models each representing different kind of behavior. These models will not be trained simultaneously to the PPO. I want the PPO encounter all these different models during training, meaning: I want to switch out the 'teammate' of the PPO every x amount of epochs. How do I do this?
I am using the overcooked-ai environment. All code would be too much to include. But the generation of the trainer ends up returning this:
trainer = PPOTrainer(env="overcooked_multi_agent", config={
"multiagent": multi_agent_config,
"callbacks" : TrainingCallbacks,
"custom_eval_function" : get_rllib_eval_function(evaluation_params, environment_params['eval_mdp_params'], environment_params['env_params'],
environment_params["outer_shape"], 'ppo', 'ppo' if self_play else 'bc',
verbose=params['verbose']),
"env_config" : environment_params,
"eager" : False,
**training_params
}, logger_creator=custom_logger_creator
and the multi-agent-config is created like
def gen_policy(policy_type="ppo"):
# supported policy types thus far
assert policy_type in ["ppo", "bc"]
if policy_type == "ppo":
config = {
"model" : {
"custom_options" : model_params,
"custom_model" : "MyPPOModel"
}
}
return (None, env.ppo_observation_space, env.action_space, config)
elif policy_type == "bc":
bc_cls = bc_params['bc_policy_cls']
bc_config = bc_params['bc_config']
return (bc_cls, env.bc_observation_space, env.action_space, bc_config)
# Rllib compatible way of setting the directory we store agent checkpoints in
logdir_prefix = "{0}_{1}_{2}".format(params["experiment_name"], params['training_params']['seed'], timestr)
def custom_logger_creator(config):
"""Creates a Unified logger that stores results in <params['results_dir']>/<params["experiment_name"]>_<seed>_<timestamp>
"""
results_dir = params['results_dir']
if not os.path.exists(results_dir):
try:
os.makedirs(results_dir)
except Exception as e:
print("error creating custom logging dir. Falling back to default logdir {}".format(DEFAULT_RESULTS_DIR))
results_dir = DEFAULT_RESULTS_DIR
logdir = tempfile.mkdtemp(
prefix=logdir_prefix, dir=results_dir)
logger = UnifiedLogger(config, logdir, loggers=None)
return logger
# Create rllib compatible multi-agent config based on params
multi_agent_config = {}
all_policies = ['ppo']
# Whether both agents should be learned
self_play = iterable_equal(multi_agent_params['bc_schedule'], OvercookedMultiAgent.self_play_bc_schedule)
if not self_play:
all_policies.append('bc')
multi_agent_config['policies'] = { policy : gen_policy(policy) for policy in all_policies }
def select_policy(agent_id):
if agent_id.startswith('ppo'):
return 'ppo'
if agent_id.startswith('bc'):
return 'bc'
multi_agent_config['policy_mapping_fn'] = select_policy
multi_agent_config['policies_to_train'] = 'ppo'
Do I already change my configuration to include multiple BHC models (code above is built to handle 1), or can I somehow change the models in the trainingloop?
Any ideas would be super helpful!

Vulkan validation warning catch-22 about VK_KHR_portability_subset on MoltenVK

I'm using Vulkan 1.2.170 with MoltenVK (and GLFW) on Big Sur (mid 2014 15" Retina). I created the instance with VK_LAYER_KHRONOS_validation and when I call vkCreateDevice I get the warning
VUID-VkDeviceCreateInfo-pProperties-04451(ERROR / SPEC): msgNum: 976972960 - Validation Error:
[ VUID-VkDeviceCreateInfo-pProperties-04451 ] Object 0: handle = 0x10cfaad00,
type = VK_OBJECT_TYPE_PHYSICAL_DEVICE; | MessageID = 0x3a3b6ca0 | vkCreateDevice:
VK_KHR_portability_subset must be enabled because physical device VkPhysicalDevice 0x10cfaad00[]
supports it The Vulkan spec states: If the [VK_KHR_portability_subset] extension is included in
pProperties of vkEnumerateDeviceExtensionProperties, ppEnabledExtensions must include
"VK_KHR_portability_subset".
Okay, fine, I add it to the extensions parameter as the only extension. Then it says
Missing extension required by the device extension VK_KHR_portability_subset:
VK_KHR_get_physical_device_properties2.
and segfaults. If I add VK_KHR_get_physical_device_properties2, it crashes saying it doesn't exist, which is true (vkEnumerateDeviceExtensionProperties doesn't return it).
Is this a bug or is there some set of extensions it will accept?
If it helps, the supported extensions are
VK_KHR_16bit_storage VK_KHR_8bit_storage VK_KHR_bind_memory2 VK_KHR_create_renderpass2 VK_KHR_dedicated_allocation VK_KHR_depth_stencil_resolve VK_KHR_descriptor_update_template VK_KHR_device_group VK_KHR_driver_properties VK_KHR_external_fence VK_KHR_external_memory VK_KHR_external_semaphore VK_KHR_get_memory_requirements2 VK_KHR_image_format_list VK_KHR_maintenance1 VK_KHR_maintenance2 VK_KHR_maintenance3 VK_KHR_multiview VK_KHR_portability_subset VK_KHR_push_descriptor VK_KHR_relaxed_block_layout VK_KHR_sampler_mirror_clamp_to_edge VK_KHR_sampler_ycbcr_conversion VK_KHR_shader_draw_parameters VK_KHR_shader_float16_int8 VK_KHR_storage_buffer_storage_class VK_KHR_swapchain VK_KHR_swapchain_mutable_format VK_KHR_timeline_semaphore VK_KHR_uniform_buffer_standard_layout VK_KHR_variable_pointers VK_EXT_debug_marker VK_EXT_descriptor_indexing VK_EXT_fragment_shader_interlock VK_EXT_hdr_metadata VK_EXT_host_query_reset VK_EXT_image_robustness VK_EXT_inline_uniform_block VK_EXT_memory_budget VK_EXT_private_data VK_EXT_robustness2 VK_EXT_scalar_block_layout VK_EXT_shader_viewport_index_layer VK_EXT_subgroup_size_control VK_EXT_texel_buffer_alignment VK_EXT_vertex_attribute_divisor VK_AMD_gpu_shader_half_float VK_AMD_negative_viewport_height VK_AMD_shader_trinary_minmax VK_INTEL_shader_integer_functions2 VK_GOOGLE_display_timing VK_NV_glsl_shader
Turns out VK_KHR_get_physical_device_properties2 is an instance extension, not a device extension, so it's passed to vkCreateInstance like so:
VkInstanceCreateInfo instCreateInfo;
const char* instExtension = "VK_KHR_get_physical_device_properties2";
instCreateInfo.enabledExtensionCount = 1;
instCreateInfo.ppEnabledExtensionNames = &instExtension;
// etcetera
VkInstance instance;
vkCreateInstance(&instCreateInfo, nullptr, &instance);
// ...
VkDeviceCreateInfo deviceCreateInfo;
const char* deviceExtension = "VK_KHR_portability_subset";
deviceCreateInfo.enabledExtensionCount = 1;
deviceCreateInfo.ppEnabledExtensionNames = &deviceExtension;
// etcetera
VkDevice device;
vkCreateDevice(physicalDevice, &deviceCreateInfo, nullptr, &device);
A bit late to answer this question. But I faced the same issue and used vk::enumerateInstanceExtensionProperties() and .enumerateDeviceExtensionProperties() to check if the extensions were present.

I am getting Error "Secure 3d is not configured for version Two"

I am try to implement 3d secure V2, but when I try to call the method
Secure3dService.CheckEnrollment(cardData).Execute(Secure3dVersion.Two)
I am getting error for "Secure 3d is not configured for version Two." Any one has idea about the error?
Found the solution for the above error. While configuring the 3d secure V2 in ServiceContainer do not select Secure3dVersion = Secure3dVersion.Two. I dont know but global payment api not support the Secure3dVersion.Two in the configuiration.
Below is my configuration settings
ServicesContainer.ConfigureService(new GpEcomConfig
{
MerchantId = MerchantId,
//AccountId = "ecom3ds",
AccountId = "3dsv2",
SharedSecret = SharedSecret,
ServiceUrl = V2ServiceUrl,
ChallengeNotificationUrl = "https://www.example.com/challengeNotificationUrl",
//MethodNotificationUrl = "https://www.example.com/methodNotificationUrl",
MethodNotificationUrl = "https://localhost:44345/ThreeDSecureNotification.aspx",
Secure3dVersion = Secure3dVersion.Any
});
we also included these
HostedPaymentConfig = new HostedPaymentConfig
{
Version = "2"
},
Secure3dVersion = Secure3dVersion.Two,

Why doesn't VkPhysicalDeviceVulkan{11|12}Properties contain valid data on Vulkan 1.2?

When using the function vkGetPhysicalDeviceProperties2 I pass a VkPhysicalDeviceProperties2 struct with a VkPhysicalDeviceVulkan11Properties and VkPhysicalDeviceVulkan12Properties in the pNext chain. However, after calling the function, only the vkGetPhysicalDeviceProperties2 contains valid data, the other structures in the chain contain undefined data.
When reviewing the spec, I noticed the comment about other structures Vulkan11 and Vulkan12 structures are supposed to encompass. When replacing them with their corresponding "smaller" structures and adding them to the chain. I do get valid data, which seems even stranger since I don't see what's preventing Vulkan from using the larger structures in the first place.
Note: Validation layers are silent
Info:
Vulkan SDK: 1.2.141.0
Nvidia Driver: 446.14
GPU GeForce GTX 1060 with Max-Q Design
OS: Windows 10.0.18363
Compiler: Microsoft (R) C/C++ Optimizing Compiler Version 19.26.28806 for x64
Relevant Code:
StaticArray<char const *, 1> const RequiredInstanceLayers{
"VK_LAYER_KHRONOS_validation",
};
StaticArray<char const *, 3> const RequiredInstanceExtensions{
VK_KHR_SURFACE_EXTENSION_NAME,
VK_EXT_DEBUG_UTILS_EXTENSION_NAME,
VK_KHR_WIN32_SURFACE_EXTENSION_NAME,
};
VkApplicationInfo ApplicationInfo;
ApplicationInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
ApplicationInfo.pNext = nullptr;
ApplicationInfo.pApplicationName = "Application";
ApplicationInfo.applicationVersion = VK_MAKE_VERSION(1, 0, 0);
ApplicationInfo.pEngineName = "Engine";
ApplicationInfo.engineVersion = VK_MAKE_VERSION(1, 0, 0);
ApplicationInfo.apiVersion = VK_API_VERSION_1_2;
VkInstanceCreateInfo InstanceCreateInfo;
InstanceCreateInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
InstanceCreateInfo.pNext = nullptr;
InstanceCreateInfo.flags = 0;
InstanceCreateInfo.pApplicationInfo = &ApplicationInfo;
InstanceCreateInfo.enabledLayerCount = RequiredInstanceLayers.length;
InstanceCreateInfo.ppEnabledLayerNames = RequiredInstanceLayers.data;
InstanceCreateInfo.enabledExtensionCount = RequiredInstanceExtensions.length;
InstanceCreateInfo.ppEnabledExtensionNames = RequiredInstanceExtensions.data;
vkCreateInstance(&InstanceCreateInfo, nullptr, &m_instance);
Uint32 physical_device_count;
vkEnumeratePhysicalDevices(m_instance, &physical_device_count, nullptr);
m_available_physical_devices.Create(m_allocator, physical_device_count);
vkEnumeratePhysicalDevices(m_instance, &physical_device_count, m_available_physical_devices.beg);
for (auto it = m_available_physical_devices.beg; it != m_available_physical_devices.end; ++it)
{
{ // Test 1
VkPhysicalDeviceProperties2 Properties2;
VkPhysicalDeviceVulkan11Properties Vulkan11Properties;
VkPhysicalDeviceVulkan12Properties Vulkan12Properties;
Properties2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2;
Vulkan11Properties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_PROPERTIES;
Vulkan12Properties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_PROPERTIES;
Properties2.pNext = &Vulkan11Properties;
Vulkan11Properties.pNext = &Vulkan12Properties;
Vulkan12Properties.pNext = nullptr;
vkGetPhysicalDeviceProperties2(*it, &Properties2); // only Properties2 is filled out
// Vulkan11Properties and Vulkan12Properties contain undefined data
}
{ // Test 2
VkPhysicalDeviceProperties2 Properties2;
VkPhysicalDeviceDriverProperties DriverProperties;
VkPhysicalDeviceFloatControlsProperties FloatControlsProperties;
VkPhysicalDeviceDescriptorIndexingProperties DescriptorIndexingProperties;
VkPhysicalDeviceDepthStencilResolveProperties DepthStencilResolveProperties;
VkPhysicalDeviceSamplerFilterMinmaxProperties SamplerFilterMinmaxProperties;
VkPhysicalDeviceTimelineSemaphoreProperties TimelineSemaphoreProperties;
VkPhysicalDeviceIDProperties IDProperties;
VkPhysicalDeviceSubgroupProperties SubgroupProperties;
VkPhysicalDevicePointClippingProperties PointClippingProperties;
VkPhysicalDeviceMultiviewProperties MultiviewProperties;
VkPhysicalDeviceProtectedMemoryProperties ProtectedMemoryProperties;
VkPhysicalDeviceMaintenance3Properties Maintenance3Properties;
Properties2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2;
DriverProperties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES;
FloatControlsProperties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FLOAT_CONTROLS_PROPERTIES;
DescriptorIndexingProperties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_PROPERTIES;
DepthStencilResolveProperties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_STENCIL_RESOLVE_PROPERTIES;
SamplerFilterMinmaxProperties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_FILTER_MINMAX_PROPERTIES;
TimelineSemaphoreProperties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TIMELINE_SEMAPHORE_PROPERTIES;
IDProperties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES;
SubgroupProperties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_PROPERTIES;
PointClippingProperties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_POINT_CLIPPING_PROPERTIES;
MultiviewProperties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES;
ProtectedMemoryProperties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_PROPERTIES;
Maintenance3Properties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_3_PROPERTIES;
Properties2.pNext = &DriverProperties;
DriverProperties.pNext = &FloatControlsProperties;
FloatControlsProperties.pNext = &DescriptorIndexingProperties;
DescriptorIndexingProperties.pNext = &DepthStencilResolveProperties;
DepthStencilResolveProperties.pNext = &SamplerFilterMinmaxProperties;
SamplerFilterMinmaxProperties.pNext = &TimelineSemaphoreProperties;
TimelineSemaphoreProperties.pNext = &IDProperties;
IDProperties.pNext = &SubgroupProperties;
SubgroupProperties.pNext = &PointClippingProperties;
PointClippingProperties.pNext = &MultiviewProperties;
MultiviewProperties.pNext = &ProtectedMemoryProperties;
ProtectedMemoryProperties.pNext = &Maintenance3Properties;
Maintenance3Properties.pNext = nullptr;
vkGetPhysicalDeviceProperties2(*it, &Properties2); // every structure is filled out
}
}
Nvidia 446.14 drivers are Vulkan 1.1. VkPhysicalDeviceVulkan11Properties and VkPhysicalDeviceVulkan12Properties both require Vulkan 1.2.
The struct are untouched, because the spec says:
Any component of the implementation (the loader, any enabled layers, and drivers) must skip over, without processing (other than reading the sType and pNext members) any extending structures in the chain not defined by core versions or extensions supported by that component.
On the other hand it is not valid usage:
Each structure present in the pNext chain must be defined at runtime either by a core version which is supported, or by an extension which is enabled.
So Validation layers should ideally be catching this. You should report this at KhronosGroup/Vulkan-ValidationLayers. The problem seems to be the layers check indiscriminately of what version it is, and what extensions are enabled.

How to pass list/array of request objects to tensorflow serving in one server call?

After loading the wide and deep model, i was able to make prediction for one request object using the map of features and then serializing it to string for predictions as shown below-
is there a way we can create a batch of requests objects and send them for prediction to tensorflow server?
Code for single prediction looks like this-
for (each feature in feature list) {
Feature feature = null;
feature = Feature.newBuilder().setBytesList(BytesList.newBuilder().addValue(ByteString.copyFromUtf8("dummy string"))).build();
if (feature != null) {
inputFeatureMap.put(name, feature);
}
}
//Converting features(in inputFeatureMap) corresponding to one request into 'Features' Proto object
Features features = Features.newBuilder().putAllFeature(inputFeatureMap).build();
inputStr = Example.newBuilder().setFeatures(features).build().toByteString();
}
TensorProto proto = TensorProto.newBuilder()
.addStringVal(inputStr)
.setTensorShape(TensorShapeProto.newBuilder().addDim(TensorShapeProto.Dim.newBuilder().setSize(1).build()).build())
.setDtype(DataType.DT_STRING)
.build();
PredictRequest req = PredictRequest.newBuilder()
.setModelSpec(ModelSpec.newBuilder()
.setName("your serving model name")
.setSignatureName("serving_default")
.setVersion(Int64Value.newBuilder().setValue(modelVer)))
.putAllInputs(ImmutableMap.of("inputs", proto))
.build();
PredictResponse response = stub.predict(req);
System.out.println(response.getOutputsMap());
Is there a way we can send the list of Features Object for predictions, something similar to this-
List<Features> = {someway to create array/list of inputFeatureMap's which can be converted to serialized string.}
For anyone stumbling here, I found a simple workaround with Example proto to do batch request. I will borrow code from this question and modify it for the batch.
Features features =
Features.newBuilder()
.putFeature("Attribute1", feature("A12"))
.putFeature("Attribute2", feature(12))
.putFeature("Attribute3", feature("A32"))
.putFeature("Attribute4", feature("A40"))
.putFeature("Attribute5", feature(7472))
.putFeature("Attribute6", feature("A65"))
.putFeature("Attribute7", feature("A71"))
.putFeature("Attribute8", feature(1))
.putFeature("Attribute9", feature("A92"))
.putFeature("Attribute10", feature("A101"))
.putFeature("Attribute11", feature(2))
.putFeature("Attribute12", feature("A121"))
.putFeature("Attribute13", feature(24))
.putFeature("Attribute14", feature("A143"))
.putFeature("Attribute15", feature("A151"))
.putFeature("Attribute16", feature(1))
.putFeature("Attribute17", feature("A171"))
.putFeature("Attribute18", feature(1))
.putFeature("Attribute19", feature("A191"))
.putFeature("Attribute20", feature("A201"))
.build();
Example example = Example.newBuilder().setFeatures(features).build();
String pfad = System.getProperty("user.dir") + "\\1511523781";
try (SavedModelBundle model = SavedModelBundle.load(pfad, "serve")) {
Session session = model.session();
final String xName = "input_example_tensor";
final String scoresName = "dnn/head/predictions/probabilities:0";
try (Tensor<String> inputBatch = Tensors.create(new byte[][] {example.toByteArray(), example.toByteArray(), example.toByteArray(), example.toByteArray()});
Tensor<Float> output =
session
.runner()
.feed(xName, inputBatch)
.fetch(scoresName)
.run()
.get(0)
.expect(Float.class)) {
System.out.println(Arrays.deepToString(output.copyTo(new float[4][2])));
}
}
Essentially you can pass each example as an object in byte[4][] and you will receive the result in the same shape float[4][2]