Question about THC\THC.h

ZHM: <p>I cloned a project from github which is NVlabs/wetectron.<br>
And I follow the instruction to set the environment.<br>
The ninja version is 1.10.2.3<br>
conda version is 4.4.10<br>
I use the following commend to download pytorch:<br>
<em>conda install pytorch torchvision torchaudio cudatoolkit=10.2 -c pytorch</em><br>
so I got pytorch-1.11.0 and cuda-10.2<br>
And then I clone the apex from nvidia, things still work pretty well now<br>
and when I install the ninja with symbolic links<br>
Failed occur:<br>
fatal error: THC/THC.h: No such file or directory<br>
and another error is<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/6/4/645228b5050d38eda2f954e0c7d7bd49e5a25ff0.png" data-download-href="https://discuss.pytorch.org/uploads/default/645228b5050d38eda2f954e0c7d7bd49e5a25ff0" title="final"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/6/4/645228b5050d38eda2f954e0c7d7bd49e5a25ff0_2_690x456.png" alt="final" data-base62-sha1="ejtLRfl44laSWBELAbTNex0VWNi" width="690" height="456" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/6/4/645228b5050d38eda2f954e0c7d7bd49e5a25ff0_2_690x456.png, https://discuss.pytorch.org/uploads/default/optimized/3X/6/4/645228b5050d38eda2f954e0c7d7bd49e5a25ff0_2_1035x684.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/6/4/645228b5050d38eda2f954e0c7d7bd49e5a25ff0_2_1380x912.png 2x" data-dominant-color="3A182F"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">final</span><span class="informations">1475×975 209 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p>I search in google but I didn’t found anything useful.<br>
I am not sure about it was caused by version or I can just simply download the file and paste it somewhere</p>

ZHM: <p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/3/f/3f8e449808f9598190c2f652eb47374b8f3ab3b6.png" data-download-href="https://discuss.pytorch.org/uploads/default/3f8e449808f9598190c2f652eb47374b8f3ab3b6" title="error"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/3/f/3f8e449808f9598190c2f652eb47374b8f3ab3b6_2_690x157.png" alt="error" data-base62-sha1="94eT4DOykWHethJMJ9uSitkcvem" width="690" height="157" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/3/f/3f8e449808f9598190c2f652eb47374b8f3ab3b6_2_690x157.png, https://discuss.pytorch.org/uploads/default/optimized/3X/3/f/3f8e449808f9598190c2f652eb47374b8f3ab3b6_2_1035x235.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/3/f/3f8e449808f9598190c2f652eb47374b8f3ab3b6_2_1380x314.png 2x" data-dominant-color="45253B"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">error</span><span class="informations">1659×379 114 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>

ptrblck: <p>The TH/THC namespace is dead and apex also removed it already, so you should update apex to the latest version.</p>

ZHM: <p>Really appreciate for your help, but I think the problem is not caused by apex. I removed the conda environment and clone the apex using<br>
<em>git clone <a href="https://github.com/NVIDIA/apex.git" class="inline-onebox" rel="noopener nofollow ugc">GitHub - NVIDIA/apex: A PyTorch Extension: Tools for easy mixed precision and distributed training in Pytorch</a></em><br>
and install it follow the commend as follow:<br>
<em>pip install -v --disable-pip-version-check --no-cache-dir --global-option="–cpp_ext" --global-option="–cuda_ext" ./</em><br>
The error is still the same, but I found that, it is some csrc/cuda/***.cu file couldn’t find the THC, for example :SigmoidFocalLoss_cuda.cu  deform_pool_cuda.cu ROIPool_cuda.cu. Maybe I can find a newer version of these function somewhere? Or any advice I can solve if.</p>

ptrblck: <p>I might have misunderstood the issue as I thought you are running into the building error in apex.<br>
Based on the function names, it seems you are trying to build <code>maskrcnn_benchmark</code>, which still uses the deprecated import <a href="https://github.com/facebookresearch/maskrcnn-benchmark/blob/57eec25b75144d9fb1a6857f32553e1574177daf/maskrcnn_benchmark/csrc/cuda/SigmoidFocalLoss_cuda.cu#L8">here</a> so you might either want to update it or skip its build.</p>

ZHM: <p>Thank you for your help, I think I have solve the problem. It is caused by version of torch and cudatool. I reinstall pytorch for many times from 1.01 to 1.4 to 1.6 and the project can work now. Besides, I wonder why when I use conda commend to install pytorch and I get the cpu only version.</p>

moawiya_guinoubi: <p>i am currently facing the same problem, can you tell me what version of cuda and pytorch you used so i could solve it ?</p>

Kia_Davari: <p>Hi there, I have the same issue with building the mmdetection. Could you tell me how can I update it?<br>
Thank you so much</p>

ptrblck: <p>You could check which deprecated <code>TH(C)</code> methods are currently used in the code base and migrate them to the new <code>ATen</code> API. I would guess that the majority of actual function names should be equal but in a new namespace now (or without the <code>TH</code> tag in their name).</p>

ZHM: <p>Cuda verison is 10.2, pytorch version is 1.6.0. remember to use the pip install commend from official website to install pytorch.</p>

Peanpepu: <p>Im trying to compile a convolutional layer repository named “DCNv2” and have the same problem. I have installed CUDA 11.3 (docker image) and pytorch 1.12 and i have tried many things but any of them can solve it. I cant use another pytorch version because my gpu driver isnt compatible with cuda 11.6 (the other option for downloading pytorch) and my gpu isnt compatible with higher driver versions. I have tried to update ATen version but i havent found a higher version. I would appreciate any help. Thanks in advance.</p>

ptrblck: <p>PyTorch is compatible for all CUDA versions &gt;= 10.2 at the moment, so you can pick whichever version would work for you.<br>
As already described, the TH/THC namespace is deprecated and functions from it were moved to the ATen namespace. To fix build issues, check which TH(C) methods are used in the repository you are trying to build and move them to the new ATen calls.</p>

AltmanMe: <p>Hi there, I am looking for the replacement of <strong>THCudaCheck</strong>. Could you provide any clues for it?</p>

ptrblck: <p>The macro <code>AT_CUDA_CHECK</code> should work.</p>

AltmanMe: <p>Hi <a class="mention" href="/u/ptrblck">@ptrblck</a>, thank you for the quick response! I have also figured out a solution from this post. I do have another general question about how to find out which ATen calls are for which TH(C) calls? Are there more guidance or tutorial?</p><aside class="onebox githubpullrequest" data-onebox-src="https://github.com/pytorch/pytorch/pull/66391">
  <header class="source">

      <a href="https://github.com/pytorch/pytorch/pull/66391" target="_blank" rel="noopener nofollow ugc">github.com/pytorch/pytorch</a>
  </header>

  <article class="onebox-body">
    <div class="github-row">
  <div class="github-icon-container" title="Pull Request">
    <svg width="60" height="60" class="github-icon" viewbox="0 0 12 16" aria-hidden="true"><path d="M11 11.28V5c-.03-.78-.34-1.47-.94-2.06C9.46 2.35 8.78 2.03 8 2H7V0L4 3l3 3V4h1c.27.02.48.11.69.31.21.2.3.42.31.69v6.28A1.993 1.993 0 0 0 10 15a1.993 1.993 0 0 0 1-3.72zm-1 2.92c-.66 0-1.2-.55-1.2-1.2 0-.65.55-1.2 1.2-1.2.65 0 1.2.55 1.2 1.2 0 .65-.55 1.2-1.2 1.2zM4 3c0-1.11-.89-2-2-2a1.993 1.993 0 0 0-1 3.72v6.56A1.993 1.993 0 0 0 2 15a1.993 1.993 0 0 0 1-3.72V4.72c.59-.34 1-.98 1-1.72zm-.8 10c0 .66-.55 1.2-1.2 1.2-.65 0-1.2-.55-1.2-1.2 0-.65.55-1.2 1.2-1.2.65 0 1.2.55 1.2 1.2zM2 4.2C1.34 4.2.8 3.65.8 3c0-.65.55-1.2 1.2-1.2.65 0 1.2.55 1.2 1.2 0 .65-.55 1.2-1.2 1.2z"></path></svg>
  </div>

  <div class="github-info-container">
    <h4>
      <a href="https://github.com/pytorch/pytorch/pull/66391" target="_blank" rel="noopener nofollow ugc">Remove THCGeneral.cpp</a>
    </h4>

    <div class="branches">
      <code>pytorch:gh/peterbell10/172/base</code> ← <code>pytorch:gh/peterbell10/172/head</code>
    </div>

    <div class="github-info">
      <div class="date">
        opened <span class="discourse-local-date" data-format="ll" data-date="2021-10-10" data-time="22:59:34" data-timezone="UTC">10:59PM - 10 Oct 21 UTC</span>
      </div>

      <div class="user">
        <a href="https://github.com/peterbell10" target="_blank" rel="noopener nofollow ugc">
          <img alt="peterbell10" src="https://avatars.githubusercontent.com/u/13238737?v=4" class="onebox-avatar-inline" width="20" height="20">
          peterbell10
        </a>
      </div>

      <div class="lines" title="5 commits changed 13 files with 11 additions and 196 deletions">
        <a href="https://github.com/pytorch/pytorch/pull/66391/files" target="_blank" rel="noopener nofollow ugc">
          <span class="added">+11</span>
          <span class="removed">-196</span>
        </a>
      </div>
    </div>
  </div>
</div>

  <div class="github-row">
    <p class="github-body-container">Stack from [ghstack](https://github.com/ezyang/ghstack):
* __-&gt;__ #66391
* #66<span class="show-more-container"><a href="https://github.com/pytorch/pytorch/pull/66391" target="_blank" rel="noopener nofollow ugc" class="show-more">…</a></span><span class="excerpt hidden">480
* #66390
* #66389
* #66388

BC-breaking note: removes THCudaCheck. Replace it with C10_CUDA_CHECK
Differential Revision: [D31547709](https://our.internmc.facebook.com/intern/diff/D31547709)</span></p>
  </div>

  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>


ptrblck: <p>Often the function name is the same and the namespace was just moved so you could remove the TH(C) from the operation and search for this op in the source code. If that doesn’t give you any matches, search for the TH(C) method and try to find the commit which moved it. I don’t think there is any mapping or so of all moved functions.</p>

AltmanMe: <p>Awesome! It is very helpful!!</p>

rocksyne: <p>What would be the replacement of <strong>THCCeilDiv</strong> in the ATen namespace, please?</p>

rocksyne: <p>I found it. First <span class="hashtag-raw">#include</span> &lt;ATen/ceil_div.h&gt;, and then at::ceil_divide() <img src="https://discuss.pytorch.org/images/emoji/apple/blush.png?v=12" title=":blush:" class="emoji" alt=":blush:" loading="lazy" width="20" height="20"></p>

devfullstackbr: <p>hi, I’m trying to compile dcnv2, and I’m getting the error that this lib is not found. Can anybody help me?</p>