Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compile errors in cpp code #1180

Open
AntonyM55 opened this issue Aug 8, 2023 · 1 comment
Open

compile errors in cpp code #1180

AntonyM55 opened this issue Aug 8, 2023 · 1 comment

Comments

@AntonyM55
Copy link

AntonyM55 commented Aug 8, 2023

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));

@AntonyM55 AntonyM55 changed the title compile erros in cpp code compile errors in cpp code Aug 8, 2023
@msaroufim
Copy link
Member

Wanna send out a PR? We also dont have any good tests for the C++ code so would love to merge something here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants