Skip to content

compile errors in cpp code  #1180

Open
Open
@AntonyM55

Description

@AntonyM55

Context

  • Pytorch version: libtorch-macos-2.0.1.zip
  • Operating System and version: macos 13.4.1 (c)

Your Environment

  • Installed using source? [yes/no]: no
  • Are you planning to deploy it using docker container? [yes/no]: no
  • Is it a CPU or GPU environment?: CPU
  • Which example are you using: cpp/custom-dataset, cpp/distributed
  • Link to code or data to repro [if any]: 741de70

Current Behavior

build custom-dataset, get 3 error
build distributed, get 2 error

Possible Solution

project custom-dataset:
error 1 and 2 because std::random_shuffle no longer exists in C++17, so I fixed std::random_shuffle with std::shuffle

e.g.
change
std::random_shuffle(train.begin(), train.end());
std::random_shuffle(test.begin(), test.end());

to
std::random_device rd;
std::mt19937 seed_train(rd());
std::mt19937 seed_test(rd());
std::shuffle(train.begin(), train.end(), seed_train);
std::shuffle(test.begin(), test.end(), seed_test);

I can't fix the 3rd error.

project distributed:

  1. change
    #include <c10d/ProcessGroupMPI.hpp>
    to
    #include <torch/csrc/distributed/c10d/ProcessGroupMPI.hpp>

  2. at line 52
    auto pg = c10d::ProcessGroupMPI::createProcessGroupMPI();
    return type is c10::intrusive_ptr

and in function waitWork, the type is
void waitWork(std::shared_ptrc10d::ProcessGroupMPI pg, std::vector<std::shared_ptrc10d::ProcessGroupMPI::WorkMPI> works)

so I changed waitWork to
void waitWork(c10::intrusive_ptrc10d::ProcessGroupMPI pg, std::vector<c10::intrusive_ptrc10d::ProcessGroupMPI::WorkMPI> works)

and get 2 error

/opt/libtorch/include/c10/util/intrusive_ptr.h:348:13: error: no matching function for call to 'assign_ptr_'

I can't fix the error.

Steps to Reproduce

cd custom-dataset
mkdir build
cd build
cmake -DCMAKE_PREFIX_PATH=/opt/libtorch ..
make
...
cd distributed
mkdir build
cd build
cmake -DCMAKE_PREFIX_PATH=/opt/libtorch ..
make

Failure Logs [if any]

/Users/anthony/Rnd/gits/pytorch/examples/cpp/custom-dataset/custom-dataset.cpp:90:8: error: no member named 'random_shuffle' in namespace 'std'
std::random_shuffle(train.begin(), train.end());

/Users/anthony/Rnd/gits/pytorch/examples/cpp/custom-dataset/custom-dataset.cpp:91:8: error: no member named 'random_shuffle' in namespace 'std'
std::random_shuffle(test.begin(), test.end());

/Users/anthony/Rnd/gits/pytorch/examples/cpp/custom-dataset/custom-dataset.cpp:122:15: error: no matching constructor for initialization of 'torch::nn::Functional'
push_back(Functional(torch::log_softmax, 1, torch::nullopt));

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions