Skip to content

Commit d2fc1eb

Browse files
committed
added detection for invalid command queue index (this corresponds to the number of queues that can be submitted to an engine)
1 parent 80d280a commit d2fc1eb

3 files changed

Lines changed: 27 additions & 3 deletions

File tree

‎backends/ze/ze_validator_entry_exit_helpers.rb‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
require 'ze_validator_zemodel'
22
require 'ze_library'
33

4+
def check_valid_index_for_ordinal(state,ctx,queue_handle,ordinal,index)
5+
#puts "entered"
6+
if state.device_properties
7+
command_queue_prop = state.device_properties["devices"][0]["command_queue_groups"]
8+
command_queue_prop.each do |prop|
9+
if prop["ordinal"] == ordinal && (index >= prop["numQueues"] || index < 0)#oob index results in segfault
10+
state.print_usage_error(ctx, "command queue (#{state.get_handle_str(queue_handle)}) with ordinal = #{ordinal} was created " +
11+
"with index = #{index}. Index value should be: 0<= index < #{prop["numQueues"]}")
12+
end
13+
end
14+
end
15+
end
16+
417
def check_group_property_queued(state, ctx, defi, device)
518
#puts "device = #{device}"
619
if !(device.cmd_queue_group_properties_queried) && state.print_tracker["check_group_property"] == 0

‎backends/ze/ze_validator_function_entry_exit_callbacks.rb‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@
100100
#check if the group property was hardcoded
101101
command_queues = state.find_objects(ctx, 'command_queue')
102102
command_queue = command_queues[defi['hCommandQueue']]
103-
check_group_property_queued(state,ctx,defi,command_queue.device)
103+
if command_queue
104+
check_group_property_queued(state,ctx,defi,command_queue.device)
105+
end
104106
}
105107

106108
#When a fence signals the host, set the fence's status to signaled
@@ -242,15 +244,23 @@
242244
}
243245

244246
$on_successful_exit['zeCommandQueueCreate'] = lambda { |state, ctx, defi|
247+
#puts "create"
245248
command_queues = state.find_objects(ctx, 'command_queue')
246249
context = state.find_object(ctx, 'context', 'hContext')
247250
device = state.find_object(ctx, 'device', 'hDevice')
248251
desc_val = state.find_param(ctx, 'desc_val')
249252
desc = state.to_struct(desc_val, ZE::ZECommandQueueDesc)
250253
handle = defi['phCommandQueue_val']
251-
#puts "ordinal = #{desc[:ordinal]}"
252254
command_queues[handle] = ZEModel::CommandQueue.new(handle, context, device, desc)
253255
context.command_queues[handle] = command_queues[handle]
256+
#check_valid_index_for_ordinal(state,ctx,handle,desc[:ordinal],desc[:index])
257+
}
258+
259+
$on_erroneous_exit['zeCommandQueueCreate'] = lambda { |state, ctx, defi|
260+
desc_val = state.find_param(ctx, 'desc_val')
261+
desc = state.to_struct(desc_val, ZE::ZECommandQueueDesc)
262+
handle = state.find_param(ctx, 'phCommandQueue')
263+
check_valid_index_for_ordinal(state,ctx,handle,desc[:ordinal],desc[:index])
254264
}
255265

256266
$on_successful_exit['zeCommandQueueDestroy'] = lambda { |state, ctx, defi|

‎backends/ze/ze_validator_state_object.rb‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ def on_exit(m,hostname,context,defi)
283283

284284
#check if the return code indicates successful return from the API call
285285
if validate_result(defi)
286-
l = $on_successful_exit[m[1]]
286+
l = $on_successful_exit[m[1]] #This might be a problem for tracking erroneous exits.
287287
l.call(self, context, defi) if l
288288
else
289289
l = $on_erroneous_exit[m[1]]
@@ -313,6 +313,7 @@ def consume = lambda { |iterator, _|
313313
if m[2] == 'entry'
314314
on_entry(m, hostname, context, defi)
315315
elsif m[2] == 'exit'
316+
puts "#{m[1]}"
316317
on_exit(m, hostname, context, defi)
317318
end
318319
end

0 commit comments

Comments
 (0)