@@ -13,7 +13,8 @@ namespace partitioning {
1313at::Tensor generateSingleInput (
1414 ir::Input& input,
1515 c10::optional<at::ScalarType>& type_opt,
16- const ir::ShapeMode& shape_mode) {
16+ const ir::ShapeMode& shape_mode,
17+ int64_t gpu_id) {
1718 nvinfer1::Dims input_shape = input.input_shape ;
1819 if (input.input_is_dynamic ) {
1920 if (shape_mode == ir::ShapeMode::kMIN ) {
@@ -42,15 +43,17 @@ at::Tensor generateSingleInput(
4243
4344 // Make the value range for input tensor a uniform (float) distribution
4445 // 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);
4648
4749 return in;
4850}
4951
5052std::unordered_map<const torch::jit::Value*, torch::jit::IValue> generateRandomInputs (
5153 std::unordered_map<const torch::jit::Value*, std::vector<ir::Input>>& inputs,
5254 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) {
5457 // generate random inputs for running pytorch segments
5558 std::unordered_map<const torch::jit::Value*, torch::jit::IValue> ivalue_map;
5659
@@ -59,21 +62,21 @@ std::unordered_map<const torch::jit::Value*, torch::jit::IValue> generateRandomI
5962 c10::TypePtr elementType = c10::TensorType::get ();
6063 auto generic_list = c10::impl::GenericList (elementType);
6164 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 );
6366 generic_list.push_back (in.clone ());
6467 }
6568 ivalue_map[input.first ] = c10::IValue (generic_list);
6669 } else if (input.first ->type ()->kind () == torch::jit::TypeKind::TupleType) {
6770 // create tuple
6871 std::vector<torch::jit::IValue> list;
6972 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 );
7174 list.push_back (in.clone ());
7275 }
7376 auto tuple = c10::ivalue::Tuple::create (list); // create tuple ptr
7477 ivalue_map[input.first ] = c10::IValue (tuple);
7578 } 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 );
7780 ivalue_map[input.first ] = in.clone ();
7881 }
7982 }
0 commit comments