@@ -13,7 +13,8 @@ namespace partitioning {
13
13
at::Tensor generateSingleInput (
14
14
ir::Input& input,
15
15
c10::optional<at::ScalarType>& type_opt,
16
- const ir::ShapeMode& shape_mode) {
16
+ const ir::ShapeMode& shape_mode,
17
+ int64_t gpu_id) {
17
18
nvinfer1::Dims input_shape = input.input_shape ;
18
19
if (input.input_is_dynamic ) {
19
20
if (shape_mode == ir::ShapeMode::kMIN ) {
@@ -42,15 +43,17 @@ at::Tensor generateSingleInput(
42
43
43
44
// Make the value range for input tensor a uniform (float) distribution
44
45
// over [LoValIncl, HiValExcl), then cast to the desired dtype
45
- auto in = ((HiValExcl - LoValIncl) * at::rand (util::toVec (input_shape), {at::kCUDA }) + LoValIncl).to (type);
46
+ auto in = ((HiValExcl - LoValIncl) * at::rand (util::toVec (input_shape)) + LoValIncl)
47
+ .to (at::Device (at::kCUDA , gpu_id), type);
46
48
47
49
return in;
48
50
}
49
51
50
52
std::unordered_map<const torch::jit::Value*, torch::jit::IValue> generateRandomInputs (
51
53
std::unordered_map<const torch::jit::Value*, std::vector<ir::Input>>& inputs,
52
54
std::unordered_map<const torch::jit::Value*, std::vector<c10::optional<at::ScalarType>>>& types,
53
- const ir::ShapeMode& shape_mode) {
55
+ const ir::ShapeMode& shape_mode,
56
+ int64_t gpu_id) {
54
57
// generate random inputs for running pytorch segments
55
58
std::unordered_map<const torch::jit::Value*, torch::jit::IValue> ivalue_map;
56
59
@@ -59,21 +62,21 @@ std::unordered_map<const torch::jit::Value*, torch::jit::IValue> generateRandomI
59
62
c10::TypePtr elementType = c10::TensorType::get ();
60
63
auto generic_list = c10::impl::GenericList (elementType);
61
64
for (size_t i = 0 ; i < input.second .size (); i++) {
62
- auto in = generateSingleInput (input.second [i], types[input.first ][i], shape_mode);
65
+ auto in = generateSingleInput (input.second [i], types[input.first ][i], shape_mode, gpu_id );
63
66
generic_list.push_back (in.clone ());
64
67
}
65
68
ivalue_map[input.first ] = c10::IValue (generic_list);
66
69
} else if (input.first ->type ()->kind () == torch::jit::TypeKind::TupleType) {
67
70
// create tuple
68
71
std::vector<torch::jit::IValue> list;
69
72
for (size_t i = 0 ; i < input.second .size (); i++) {
70
- auto in = generateSingleInput (input.second [i], types[input.first ][i], shape_mode);
73
+ auto in = generateSingleInput (input.second [i], types[input.first ][i], shape_mode, gpu_id );
71
74
list.push_back (in.clone ());
72
75
}
73
76
auto tuple = c10::ivalue::Tuple::create (list); // create tuple ptr
74
77
ivalue_map[input.first ] = c10::IValue (tuple);
75
78
} else {
76
- auto in = generateSingleInput (input.second [0 ], types[input.first ][0 ], shape_mode);
79
+ auto in = generateSingleInput (input.second [0 ], types[input.first ][0 ], shape_mode, gpu_id );
77
80
ivalue_map[input.first ] = in.clone ();
78
81
}
79
82
}
0 commit comments